4 ms·
If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall no
by rssoconnor 5y ago
If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined.
This is that part that says the result of addition is undefined unless both the original pointer and the result point to the same array object (or one past the last element).
- paskozdilar 5y agoThanks, I didn't know all of this. At the beginning of the conversation I was quite sure about C's behavior. I guess liberal compilers don't help. C is a simple language, but it is hard to get it right sometimes.
- rssoconnor 5y agoIn C, multiplying two unsigned shorts together can lead to undefined behaviour.
- josephcsible 5y agoIn case it's not obvious how this can happen, it's because the promotion rules can turn them into signed ints, and if they're big enough the product can overflow that. For more details, see https://cryptoservices.github.io/fde/2018/11/30/undefined-behavior.html https://cryptoservices.github.io/fde/2018/11/30/undefined-be...