This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: mips structure padding
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- To: Todd Malsbary <toddm at fullplaymedia dot com>
- Cc: Eric Christopher <echristo at redhat dot com>, gcc at gcc dot gnu dot org
- Date: Thu, 31 Jan 2002 21:48:39 +1100
- Subject: Re: mips structure padding
- References: <D8DFF0AFE792914996F997E68FEC3A4806138D@bunker.iobjects.com>
On 30-Jan-2002, Todd Malsbary <toddm@fullplaymedia.com> wrote:
> i've attached a testcase that i reduced as much as possible from the
> ecos sources. when the problem occurs, the c structure size is 176
> bytes and the class is 168 bytes. by setting the define at the top of
> the cpp file, both items are the same size (176). so it looks like
> making the Cyg_Alarm class a member variable affects how things get
> padded.
...
> so is this still a bug? should i go ahead and file a report?
You don't explain what you think the problem is.
Do you mean that you think it is a bug that the sizes differ?
The answer to that is no, it is not a bug, it is a feature.
Here's a simplified example.
You will get different sizes for X1 and X2 in
struct Y {
long long l;
char c1;
};
struct X1 {
struct Y y;
char c2;
} x1;
struct X2 {
long long l;
char c1;
char c2;
} x2;
`sizeof(struct Y)' needs to be a multiple of the alignment requirements
of `long long', so that the long long member is correctly aligned when
you have an array of struct Y.
In `struct X1', the `y' field needs to occupy
a full `sizeof(struct Y)' bytes, so that doing
`memset(&x1.y, sizeof(struct Y), 0)' won't clobber c2.
This means there will be some padding after c1.
But in `struct X2', there is no padding between c1 and c2.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.