Bug 12435 - Array Element Alignment
Summary: Array Element Alignment
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.2.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-28 17:22 UTC by mnmoran
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mnmoran 2003-09-28 17:22:28 UTC
The gcc mailing list thread that starts with this message
explores the issue.

http://gcc.gnu.org/ml/gcc/2003-09/msg01031.html


#include <stdio.h>

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

achar a[2];

int main(int argc,char* argv[]){
   printf("__alignof__(achar):%u\n",__alignof__(achar));
   printf("__alignof__(a[1]):%u\n",__alignof__(a[1]));
   printf("&a: %8.8lX\n",(unsigned long)&a);
   printf("sizeof(a):%u\n",sizeof(a));
   printf("sizeof(a[0]):%u\n",sizeof(a[0]));
   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

__alignof__(achar):32
__alignof__(a[1]):1
&a: 08049740
sizeof(a):32
sizeof(a[0]):1
&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.
Comment 1 Andrew Pinski 2003-12-28 03:32:58 UTC
alignment is only for structors and where it stored on the stack/global memory.