Re: Align attribute on struct

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

 



2010/7/7 Rodrigo Dominguez <roddomi@xxxxxxxxxxx>
>
> I am trying to ask gcc to align a struct but it is not working. Here's a
> program I wrote to show what I am trying to do:
>
> #include <stdio.h>
>
> typedef struct {
>    int a, b, c;
> } s __attribute__ ((aligned (16)));
>
> int data[] = {1, 2, 3, 4, 5, 6, 7, 8};
>
> int main(void)
> {
>    printf("%d\n", ((s *)data)[0].a);
>    printf("%d\n", ((s *)data)[1].a);
>
>    return 0;
> }
>
> Compiling with gcc 4.4.1:
>
> $ gcc test.c
> $ ./a.out
> 1
> 4
>
> I would expect the output to be 1 and 5. Am I missing something?
>
> Thank you,
>
> Rodrigo
>
Hello, Rodrigo! Sorry if I'm wrong, but, as I remember, int is 4 bytes
long, 32 bits, so the structure in your case will be "continuous". So
everything is working as it should! Regards, Ivan.



[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