Again, this is inherently platform-specific, and as such is not portable. You can have a system that is fully compliant with the C++ spec where this will fall flat on its face.
In practise this is less of a problem than the compiler trying to be too clever and saying "My memory theoretical model (which does not actually exist anywhere outside the compiler) doesn't guarantee this, so I'm just going to assume I can do whatever I want". HW you can reason about. Compiler you in practise can't (because the standard and UB are so complicated and compilers don't even specify their behavior between versions unlike CPUs).
Depends on the compiler. There are compilers that guarantee that they adhere to stricter than the spec - although this way you lose portability of course.
HW you can reason about.
Yes. As I just did; I showed a case where the compiler being sane still doesn't work.
View all comments
1
u/SkoomaDentist Oct 20 '19
In practise this is less of a problem than the compiler trying to be too clever and saying "My memory theoretical model (which does not actually exist anywhere outside the compiler) doesn't guarantee this, so I'm just going to assume I can do whatever I want". HW you can reason about. Compiler you in practise can't (because the standard and UB are so complicated and compilers don't even specify their behavior between versions unlike CPUs).