This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Align attribute on struct
- From: "ivanko.rus" <ivanko dot rus at gmail dot com>
- To: roddomi at hotmail dot com, gcc-help at gcc dot gnu dot org
- Date: Wed, 7 Jul 2010 17:40:51 -0500
- Subject: Re: Align attribute on struct
- References: <BAY151-ds35F7CA5AFAA2DC6437E02B9B30@phx.gbl> <AANLkTikZJlQvGhHN9h5BphnjNwhnDvn9ijrDwyU0Kh8W@mail.gmail.com>
2010/7/7 Rodrigo Dominguez <roddomi@hotmail.com>
>
> 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.