Clarification on Gcc's strict aliasing rules
Ian Lance Taylor
Mon Nov 8 05:29:00 GMT 2010
"Segher Boessenkool" <firstname.lastname@example.org> writes:
>> BTW, I tried to compile the last example, and we agreed that it invokes
>> undefined behaviour.
> I did no such thing. With -fno-strict-aliasing, the code is well-defined.
I think I would say this slightly differently. The code is still
undefined according to the C/C++ language standards. When you use
-fno-strict-aliasing, gcc is promising to avoid using a class of
optimizations based on those portions of the language standards.
Another way to say this is that gcc is promising to not optimize based
on the fact that memory locations are accessed using different types.
That is, the code is still incorrect; gcc is just avoiding a class of
optimizations which are known to cause trouble with real programs.
I also am having trouble understanding what the OP is asking for here.
More information about the Gcc-help