Gentoo Archives: gentoo-amd64

From: Nikos Chantziaras <realnc@×××××.de>
To: gentoo-amd64@l.g.o
Subject: [gentoo-amd64] Re: GCC-4.5.2 Has Serious Problems
Date: Thu, 30 Jun 2011 23:37:25
Message-Id: iuj17v$o6s$1@dough.gmane.org
In Reply to: [gentoo-amd64] GCC-4.5.2 Has Serious Problems by Frank Peters
1 On 07/01/2011 12:45 AM, Frank Peters wrote:
2 > Hello,
3 >
4 > After banging my head for a while over some strange results, I began
5 > to suspect GCC-4.5.2, the latest version in portage, was creating
6 > faulty code.
7 >
8 > It seems to a correct suspicion.
9 >[...]
10 > int n;
11 > double x;
12 > unsigned long int arg;
13 > unsigned long int *px = (unsigned long int*)&x;
14
15 Your code is buggy, because you're breaking C's aliasing rules. You are
16 not allowed to use a different pointer type to dereference a variable of
17 a different type. Doing so results in undefined behavior.
18
19 Short answer, GCC is correct, you are wrong :-) To compile code that
20 breaks aliasing rules, always use the "-fno-strict-aliasing" option. In
21 this case:
22
23 gcc -O2 -fno-strict-aliasing

Replies

Subject Author
[gentoo-amd64] Re: GCC-4.5.2 Has Serious Problems Nikos Chantziaras <realnc@×××××.de>