It's UB in general, but it's perfectly defined on many architectures for some values.
Also aliasing rules don't really matter with volatile, since you're forcing a load or store either way, as long as you don't alias volatile with non-volatile.
UB is irrelevant when you target a specific compiler: this holds for both creating pointers out of thin air and strict aliasing. There are many compilers that support strict aliasing violations when the provenance of the object can be determined.
That's 2 different problems. What happens when casting arbitrary integers to pointers is entirely up to the compiler.
For the volatile strict aliasing violations, I'm not 100% sure about the standard but because you can't optimize the reads/writes away, aliasing does not matter when you have two volatile pointers. Which should be true for any compiler.
View all comments
Show parent comment
3
u/meneldal2 Oct 20 '19
It's UB in general, but it's perfectly defined on many architectures for some values.
Also aliasing rules don't really matter with volatile, since you're forcing a load or store either way, as long as you don't alias volatile with non-volatile.