This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: alignment bug?
- From: Andrew Haley <aph at redhat dot com>
- To: Gagan Arneja <gaagaan at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 20 Apr 2008 10:50:25 +0100
- Subject: Re: alignment bug?
- References: <480AE3AD.5090404@gmail.com>
Gagan Arneja wrote:
> What am I doing wrong? Why is "bar" getting truncated down to 128?
>
Looks OK to me. What is the result that you expect?
> #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
>