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: Align attribute on struct


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.


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