public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/6385: sizeof fails calculating size of an structure (sizeof(struct my_struct))
@ 2002-04-20 6:46 gad
0 siblings, 0 replies; 2+ messages in thread
From: gad @ 2002-04-20 6:46 UTC (permalink / raw)
To: gcc-gnats
>Number: 6385
>Category: c
>Synopsis: sizeof fails calculating size of an structure (sizeof(struct my_struct))
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sat Apr 20 06:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Gonzalo Aguilar : gad@reymad.com
>Release: gcc-3.0.4
>Organization:
>Environment:
linux 2.4.17 glibc 2.2.3
>Description:
This structure:
struct msh_header
{
char charid[3];
int objs;
};
is evaluated as a 8 bytes size object.
It sould be 7 bytes.
It seems that aligns data to a 4 byte boundary but this is not what should happen cause structure MUST be 7.
Even this will be 8 bytes
struct msh_header
{
char charid[1];
int objs;
};
And this 12 bytes size:
struct msh_header
{
char charid[5];
int objs;
};
>How-To-Repeat:
Just compile this code
#include <stdio.h>
struct msh_header
{
char charid[3];
int objs;
};
int main(int argc, char **argv)
{
printf("Size %i should be %i",sizeof(struct msh_header),7);
return(1);
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c/6385: sizeof fails calculating size of an structure (sizeof(struct my_struct))
@ 2002-04-20 7:01 neil
0 siblings, 0 replies; 2+ messages in thread
From: neil @ 2002-04-20 7:01 UTC (permalink / raw)
To: gad, gcc-bugs, gcc-prs, nobody
Synopsis: sizeof fails calculating size of an structure (sizeof(struct my_struct))
State-Changed-From-To: open->closed
State-Changed-By: neil
State-Changed-When: Sat Apr 20 07:01:26 2002
State-Changed-Why:
Not a bug - you don't appear to understand padding
and alignment requirements.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6385
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-04-20 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-20 6:46 c/6385: sizeof fails calculating size of an structure (sizeof(struct my_struct)) gad
2002-04-20 7:01 neil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).