/* gcc-4.1.1 gives "unaligned access" on alphaev68-dec-osf5.1b regression from gcc-3.4.4 % gcc -v Using built-in specs. Target: alphaev68-dec-osf5.1b Configured with: /usr/local/gcc-4.1.1/src/gcc-4.1.1/configure --enable-languages=c --prefix=/usr/local/gcc-4.1.1/alpha-OSF1-V5 Thread model: posix gcc version 4.1.1 % % gcc -o foo foo.c % foo Unaligned access pid=141992 <foo> va=0x11fffbffc pc=0x12000115c ra=0x1200011a0 inst=0x 9d420000 % */ typedef struct { double d; } aa; int foo(v) aa *v; { v->d = (double) 1; return 0; } int main() { int cc[1]; int i1; int i2; int i3; int i4; int i5; int i6; int i7; /* if remove this line, then no problem! */ foo(cc); /* says "unaligned access" */ return 0; }
The conversion from int* to aa* is only defined if the pointer is correctly aligned. Even if it was correctly aligned, dereferencing this pointer is undefined behavior (see -Wstrict-aliasing documentation). So this is not a gcc bug.
More than that: int cc[1]; foo(cc); /* says "unaligned access" */ int foo(v) aa *v; You are also violating C aliasing rules and also violating an even more fundental problem in that the struct aa will not fit in cc.