This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Understanding alignment in g++


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]