3 ms·
>if incremented past the maximum. What would be the intention to increment past the maximum? Incrementing a number infinitely is an infinite series 1+1+1[..]
by passivate 5y ago
>if incremented past the maximum.
What would be the intention to increment past the maximum? Incrementing a number infinitely is an infinite series 1+1+1[..] A programmer needs to be aware that you cannot store an infinite series in a data type like int - and this applies to any programming language.
If the programmer is looking to exploit wrapping behavior then it is best not to ASSUME anything, but actually verify what promises the language provides. Its basic sanity checking, you do that before sending parameters to API, receiving parameters, during transfer of ownership of memory, etc, etc. All of this falls under basic programming - regardless of language.
- Etherlord87 5y ago> A programmer needs to be aware This can be extrapolated to anything that causes UB. A programmer needs to be aware that what he does causes UB. You asked for a normal thing that is being done by a programmer that causes UB, and I think I gave a fair example. I don't want to aggressively argue a point, just wondering what exactly you want to prove here. It's not like programmers cause UB intentionally or when doing some weird stuff like code golfing. No, programmers code in C++ using standard techniques and fall victim to the UB. Another example of UB is accessing an array out of bounds. Again, you may say a programmer is expected to rationalize his code in this regard, and yet off-by-one is one of the most common categories of errors in practice.
- passivate 5y ago>You asked for a normal thing that is being done by a programmer that causes UB, and I think I gave a fair example. Not really. I asked for examples where the language takes the intention of the programmer and turns it into UB. The quote that I responded to "C++ compiler generates the most efficient thing that may or may not correlate with what you intended" What is the intention of the programmer attempting to store an infinite number series in an int? In any case, I think we've run of steam here so you have the last word if you'd like.