If you stick to what is taught in any good tutorial/book, you don't even have to think about problems like this.
But if you decide to play with fire, then you should read the Standard and understand it.
If you stick to what is taught in any good tutorial/book, you don't even have to think about problems like this.
But if you decide to play with fire, then you should read the Standard and understand it.
C is not a scripting language. If you use the tools available to you, and don't abuse the language, then it is fairly hard to cause undefined behavior.
If you are using gcc, you can start with the flag: -ftrapv. It does everything for you.
If it helps: The author of that article, John Regehr, is a professor of computer science who spends a great deal of time studying undefined behaviour.
-Strawman argument.
-Appeal to authority.
Next time stick to the issue, you will find the debate will be much more rewarding for both parties.
I guess the best solution is to move to other languages (IIRC Ada and rust are relatively free from surprises in their UB) and let language lawyers optimize C to death (by attrition).
But even making sure that you stay within the valid range of your integer isn't necessarily enough; you need to check that you're still within the range without going outside of it.