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]

Re: How to stop gcc padding structs???


On Sun, 28 Jan 2001 12:56:09 -0600, Grant Edwards wrote:

  
  I'm again fighting with gcc trying (and failing) to get it to
  stop putting padding bytes into structs.  Has anybody figured
  out how to prevent gcc from padding structs?
  
  I ran into this problem before and gave up, finally having to
  use hand-calculated constants instead of "sizeof (struct foo)"
  in numerous places.  For example, it's impossible to define an
  Ethernet header structure that ends up having a size of 14
  bytes!

You have to change the alignment of the types that you're using.
The size of an object of a type is always a multiple of its alignment.
Probably you're using types like "int" with an alignment of 4 bytes,
which will cause your entire structure to have a 4 byte alignment.

Be aware that unaligned types may be very inefficient on certain machines,
as a variable access might need two reads and some shift/and/or glue.

  -Geert



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