This is the mail archive of the
mailing list for the GCC project.
Re: Question about "#pragma pack(n)" and "-fpack-struct"
- From: James E Wilson <wilson at specifixinc dot com>
- To: feng qiu <fengqiu_tianjin at hotmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 15 Mar 2005 12:13:06 -0800
- Subject: Re: Question about "#pragma pack(n)" and "-fpack-struct"
- References: <BAY16-F2083EE4BEFAC17ED62B39088550@phx.gbl>
On Sat, 2005-03-12 at 21:00, feng qiu wrote:
> Is it difficult to modify the gcc sources if I want to use the both?
The tricky part might be defining what it means. There are at least 4
interacting features here, #pragma pack, attribute ((packed)), attribute
((aligned(X)), and -fpack-struct. Currently, -fpack-struct is defined
to have the same effect as attribute ((packed)) for all structures,
which in turn is equivalent to #pragma pack(1) for all structures. If
you want -fpack-struct to mean something else, then you need to define
how these features interact. This will probably mean splitting the
current TYPE_PACKED/DECL_PACKED fields into two, one which handles
pragma pack, one which handles -fpack-struct, and attribute((packed))
can perhaps go in which ever one makes more sense. Then you need to
modify all code that uses TYPE_PACKED/DECL_PACKED appropriately, which
may be messy.
It occurs to me to mention that you can get the result you want if you
use attribute ((aligned(2)) instead of pragma pack(2). That is better
than hacking up gcc.
int x2 __attribute__ ((aligned(2)));
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com