alignment bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What am I doing wrong? Why is "bar" getting truncated down to 128?

> gcc -v
gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)



#include <stdio.h>

#define ALIGNED(n) __attribute__((__aligned__(n)))

typedef struct Bar {
   char c[200];
} Bar ALIGNED(128);

typedef struct Foo {
  Bar bar[4];
} Foo;

Foo foo[4];

main()
{
   int i;
   Foo *foop = &foo[0];

   printf("sizeof(Bar) = %d\n", sizeof(Bar));
   printf("sizeof(Foo) = %d\n", sizeof(Foo));

   for (i=0; i < 4; i++) {
      Bar *bar = &foop->bar[i];
      printf("&bar[%d]=%p, addr%128=0x%lx\n",
             i, bar, ((unsigned long)bar) % 128);
   }

}

> ./a.out
sizeof(Bar) = 200
sizeof(Foo) = 896
&bar[0]=0x8049180, addr%128=0x0
&bar[1]=0x8049200, addr%128=0x0
&bar[2]=0x8049280, addr%128=0x0
&bar[3]=0x8049300, addr%128=0x0


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux