3 ms·
This is why language standards specify what the compiler can assume and call out some behavior as undefined, exactly so compilers don't have to be paranoid and
by not2b 5y ago
This is why language standards specify what the compiler can assume and call out some behavior as undefined, exactly so compilers don't have to be paranoid and produce code that sucks. If an underlying object is const, the compiler is allowed to assume that it does not change (it is valid to cast away const on a pointer or reference, but not if the object itself was declared const).
- toast0 5y ago> (it is valid to cast away const on a pointer or reference, but not if the object itself was declared const). Isn't it valid to cast to non-const for a const, but only invalid to modify the const through the casted pointer?
- deleted 5y ago[deleted]
- why_only_15 5y agoInterestingly GCC will still optimize the loop function even if you have code that modifies the modulus. https://godbolt.org/z/EE9PnrY7s https://godbolt.org/z/EE9PnrY7s
- colonwqbang 5y agoThat code is invalid, it would give a compiler warning and possibly a runtime exception.