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:

> Is there something analogous to __alignof__ that can tell me the
> required alignment?  (E.g., if I'm serializing data and trying to pack
> together everything without padding...)

As far as I know there is no way to ask for the alignment required by
the target machine.  However, if you use __attribute__ ((packed)), then
gcc will use the available instructions to retrieve the field: a
misaligned full word read if possible and appropriate, otherwise byte
reads.

Ian


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