public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* other/5285: sizeof() doesn't work like it would with some structures
@ 2002-01-05 20:36 ceniza666
  0 siblings, 0 replies; 2+ messages in thread
From: ceniza666 @ 2002-01-05 20:36 UTC (permalink / raw)
  To: gcc-gnats

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1792 bytes --]


>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:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: other/5285: sizeof() doesn't work like it would with some structures
@ 2002-01-07  3:57 neil
  0 siblings, 0 replies; 2+ messages in thread
From: neil @ 2002-01-07  3:57 UTC (permalink / raw)
  To: ceniza666, gcc-bugs, gcc-prs, nobody

Synopsis: sizeof() doesn't work like it would with some structures

State-Changed-From-To: open->closed
State-Changed-By: neil
State-Changed-When: Mon Jan  7 03:56:56 2002
State-Changed-Why:
    GCC knows how to add bytes.
    
    However, it appears you do not know about alignment or padding 8-)
    
    Not a bug.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5285


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-01-07 11:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-05 20:36 other/5285: sizeof() doesn't work like it would with some structures ceniza666
2002-01-07  3:57 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).