This is the mail archive of the 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]

Arrays and Alignment

I am declaring an array of an aligned type. However
it would appear that when used in an array, the alignment
is not maintained as I would expect. Here's a test-case.

#include <stdio.h>

typedef unsigned char achar __attribute__ ((__aligned__(32)));

achar a[2];

int main(int argc,char* argv[]){
   printf("&a: %8.8lX\n",(unsigned long)&a);
   printf("&a[0]: %8.8lX\n",(unsigned long)&a[0]);
   printf("&a[1]: %8.8lX\n",(unsigned long)&a[1]);
   return 0;

% gcc -o main main.c ; main

&a: 08049740
&a[0]: 08049740
&a[1]: 08049741         <<<<<<<<<<<< I expected this to be 08049760

% gcc --version
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

I expected the second element of the array to be aligned
as well as the first, since the alignment of the type is 32.

The Beatles were wrong: 1 & 1 & 1 is 1

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