This is the mail archive of the
mailing list for the GCC project.
Re: Understanding alignment in g++
- From: Ian Lance Taylor <iant at google dot com>
- To: Yang Zhang <yanghatespam at gmail dot com>
- Cc: GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 13 Feb 2009 18:29:13 -0800
- Subject: Re: Understanding alignment in g++
- References: <email@example.com>
Yang Zhang <firstname.lastname@example.org> 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