On Monday 28 September 2009, Frank Mori Hess wrote: > The > strict aliasing rules allow compilers to make optimizations that assume > pointers to different types will not access the same memory. I'll try > to produce a test program soon.
Attached is an example program that shows undefined behavior due to aliasing from treating "float _Complex" and "float [2]" as interchangeable types. When compiled with on Debian Lenny (gcc 4.3.2) with "gcc -Wall -O2" the assertion fails. When compiled with "gcc -Wall -O2 -fno-strict-aliasing" the assertion passes.
#include <assert.h> #include <complex.h> #include <stdio.h> #include <stdlib.h> typedef float _Complex fftw_complex1; typedef float fftw_complex2[2]; fftw_complex2 a; int main() { fftw_complex1 *x = NULL; fftw_complex2 **p = (fftw_complex2**)(&x); *p = &a; x = NULL; assert(*p == NULL); return 0; }
signature.asc
Description: This is a digitally signed message part.