This is the mail archive of the gcc@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: Question about "#pragma pack(n)" and "-fpack-struct"


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.
struct TEST{
  char    x1;
  int    x2 __attribute__ ((aligned(2)));
};
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



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