This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
other/5285: sizeof() doesn't work like it would with some structures
- From: ceniza666 at yahoo dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 6 Jan 2002 04:31:34 -0000
- Subject: other/5285: sizeof() doesn't work like it would with some structures
- Reply-to: ceniza666 at yahoo dot com
>Number: 5285
>Category: other
>Synopsis: sizeof() doesn't work like it would with some structures
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Jan 05 20:36:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: ceniza666@yahoo.com
>Release: 3.03
>Organization:
>Environment:
DJGPP (normal installation), Windows 98 SE (spanish), 1GHz processor, Allegro 4.0.
>Description:
Two examples of ¡48! bytes structures:
typedef struct seguridad1{
char lic;
short time;
short date;
char FAT;
unsigned short suma;
char serial[4];
char nombre[36];
}seg1;
typedef struct seguridad2{
char lic;
char FAT;
short time;
short date;
unsigned short suma;
char serial[4];
char nombre[36];
}seg2;
well, this two structures are the "same", except by the position of char FAT.
if I use sizeof in the first one, it returns 50, and if I use sizeof in the second one, it returns 48, and the information is used in memory in differen ways (If I write this structures in a file, in the first one the two char vars are stored like two char vars each one, when only the first char is right of each "pair" of chars). What's the difference??? I can't believe that gcc doesn't know how to add bytes or how to manage structures.
I hope this can be solve, I need the first struct working like a 48 bytes struct, not like a 50 bytes struct.
Thanks, very cool compiler, especially for the way it use the memory (FAR).
>How-To-Repeat:
only try with these two structures with sizeof
printf("%s",(sizeof(seg1)==sizeof(seg2))?"Yes, gcc know how to add bytes":"Sorry");
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: