typedef unsigned char       u8;
typedef unsigned int       u32;
typedef unsigned long long u64;

struct x
{
    u8  x1[64];
    u64 x2;
    u32 x3;
};

#include <stdio.h>
int main()
{
    struct x x;
    printf("sizeof(x)    = %2u\n", sizeof(x));
    printf("offset(M.x1) = %2u\n", (unsigned)&x.x1 - (unsigned)&x);
    printf("sizeof(M.x1) = %2u\n", sizeof(x.x1));
    printf("offset(M.x2) = %2u\n", (unsigned)&x.x2 - (unsigned)&x);
    printf("sizeof(M.x2) = %2u\n", sizeof(x.x2));
    printf("offset(M.x3) = %2u\n", (unsigned)&x.x3 - (unsigned)&x);
    printf("sizeof(M.x3) = %2u\n", sizeof(x.x3));
    return 0;
}


with `-O2` I get:

sizeof(x)    = 80      <=  why not 76 ?
offset(M.x1) =  0
sizeof(M.x1) = 64
offset(M.x2) = 64
sizeof(M.x2) =  8
offset(M.x3) = 72
sizeof(M.x3) =  4

with `-O2 -fpack-struct`

sizeof(x)    = 76
offset(M.x1) =  0
sizeof(M.x1) = 64
offset(M.x2) = 64
sizeof(M.x2) =  8
offset(M.x3) = 72
sizeof(M.x3) =  4

why ppc (without -fpack-struct) extends this structure to 80 bytes?


-- 
           Summary: weird struct size.
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at agmk dot net
 GCC build triplet: ppc-linux
  GCC host triplet: ppc-linux
GCC target triplet: ppc-linux


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

Reply via email to