List Archive: gentoo-amd64
Note: Due to technical difficulties, the Archives are currently not up to date.
provides an alternative service for most mailing lists.c.f. bug 424647
On 07/01/2011 12:45 AM, Frank Peters wrote:
> After banging my head for a while over some strange results, I began
> to suspect GCC-4.5.2, the latest version in portage, was creating
> faulty code.
> It seems to a correct suspicion.
> int n;
> double x;
> unsigned long int arg;
> unsigned long int *px = (unsigned long int*)&x;
Your code is buggy, because you're breaking C's aliasing rules. You are
not allowed to use a different pointer type to dereference a variable of
a different type. Doing so results in undefined behavior.
Short answer, GCC is correct, you are wrong :-) To compile code that
breaks aliasing rules, always use the "-fno-strict-aliasing" option. In
gcc -O2 -fno-strict-aliasing