> It will load the value from memory, true, but who says that the store to
> memory will happen before that?  The compiler is allowed to reorder the
> statements since it "knows" that foo and *arg cannot alias.
>

If the compiler is smart enough to know how to reorder the statements,
then it should be smart enough to know that reordering will still leave
foo uninitialized, which is obviously an error.

It's also undefined, so we can *and will* reorder things involving
uninitialized variables.
 Any time an
optimization/reordering visibly changes the results, that reordering is
broken.
Not in this case.
also Note that gcc *guarantees* the union trick will work, even though
the standard does not.

And we already know that gcc is smart enough to recognize
attempts to use uninitialized variables, so there's no reason for it to
go there.
We already do, particularly when it comes to constant propagation

Relying on the idea that "oh, well, this is uninitialized, so the
compiler can't touch it" is going to get you hurt one of these days :)

Reply via email to