Understanding alignment in g++
Ian Lance Taylor
iant@google.com
Sat Feb 14 02:29:00 GMT 2009
Yang Zhang <yanghatespam@gmail.com> writes:
> I expected a cast-align warning or something.
If you use -Wcast-align you should get a warning for targets where the
cast increases the required alignment.
> How did gcc make the unaligned write work?
You appear to be compiling for the x86. The x86 supports misaligned
accesses for basic types. The instructions do what you expect, though
in some cases they will take a few more clock cycles.
> Related: Is there an example of a type that actually has non-1
> alignment on x86(_64)?
There are SSE instructions which required aligned memory addresses
(there are also less efficient SSE instructions which permit misaligned
memory addresses).
Ian
More information about the Gcc-help
mailing list