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: mips structure padding


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.


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