by aciuix · 11y ago · 0 comments
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.
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.