public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31670]  New: Error calculating size of structs
@ 2007-04-23 18:26 padrinator at gmail dot com
  2007-04-23 18:33 ` [Bug c/31670] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: padrinator at gmail dot com @ 2007-04-23 18:26 UTC (permalink / raw)
  To: gcc-bugs

#include <stdio.h>

typedef struct{
        char data[261];
        int n;
} packet;

int main(int argc, char *argv[]){
        packet p;

        //It should print packet=265... it prints packet=268
        printf("packet = %d\n", sizeof(packet)); 
        //It should print p=265... it prints p=268
        printf("p = %d\n", sizeof(p));
        //It should print p.n=4... OK
        printf("p.n = %d\n", sizeof(p.n));
        //It should print p.data=261... OK
        printf("p.data = %d\n", sizeof(p.data));
        return 0;
}


-- 
           Summary: Error calculating size of structs
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: padrinator at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31670


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

* [Bug c/31670] Error calculating size of structs
  2007-04-23 18:26 [Bug c/31670] New: Error calculating size of structs padrinator at gmail dot com
@ 2007-04-23 18:33 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-23 18:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-04-23 19:32 -------
Learn about alignment when doing struct layout.  Basically you want to use the
attribute packed to get the sizes you want.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31670


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

end of thread, other threads:[~2007-04-23 18:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-23 18:26 [Bug c/31670] New: Error calculating size of structs padrinator at gmail dot com
2007-04-23 18:33 ` [Bug c/31670] " pinskia at gcc dot gnu dot org

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).