Hm. If you're going to reorder these things, then I would expect either an error or a warning at that point, because you really do know that a reference to an uninitialized variable is happening.
We do warn when we see an uninitialized value if -Wuninitialized is on. We don't warn at every point we make an optimization based on it, nor do i think we should :)
> also Note that gcc *guarantees* the union trick will work, even though > the standard does not. That's good to know, thanks. But frankly that's braindead to require someone to add all these new union declarations all over their code, when a simple cast used to suffice, and ultimately the generated code is the same. And since we have to write code for compilers other than just gcc, we can't even really rely on the union trick. In this respect, the standard is broken. This example is worse, it gives no warning and gives the wrong result with -O3 -Wstrict-aliasing : #### #include <stdio.h> main() { int i = 0x123456; int *p = &i; *(short *)p = 2; printf("%x\n", i); } #### In this case, it's not two different pointers pointing to the same memory, it's the same pointer. The compiler doesn't even have to guess whether two different pointers access the same memory - it knows it's the same pointer, understand strange results occurring when there's ambiguity, but there is no ambiguity here.
You are right, there isn't. We ask the TBAA analyzer "can a store to a short * touch i. In this case, it says "no", because it's not legal.