This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: alignment bug?


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
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]