data alignment

Michael Meissner meissner@cygnus.com
Tue Sep 12 17:52:00 GMT 2000


On Tue, Sep 12, 2000 at 05:31:39PM -0400, Silvio Bandeira wrote:
> Hi guys,
> 
>     Do you know how to control arrays and structures alignment using gcc
> ? I need them "packed".
>     I've used "__attribute__ ((packed))" after defining a struct, but it
> decreases portability. Is there a more "clean" way to specify that for
> all data structures?
>     I've also tried "#pragma pack(1)" but gcc says "ignoring pragma".
>     Thanks in advance for any information.

There is no 'clean' method of doing this.  In fact, many compilers offer no
means of overriding the default packing rules.  Also note, that you can't even
be guaranteed that an unsigned char is 8 bits (though it will be true in many
machines, but not all, including some machines that GCC targets).

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


More information about the Gcc mailing list