This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to stop gcc padding structs???
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>,"Grant Edwards" <grante at visi dot com>
- Subject: Re: How to stop gcc padding structs???
- From: "Geert Bosch" <bosch at gnat dot com>
- Date: Sun, 28 Jan 2001 17:51:04 -0500
- Reply-To: "Geert Bosch" <bosch at gnat dot com>
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