1 |
On 07/01/2011 02:35 AM, Nikos Chantziaras wrote: |
2 |
> On 07/01/2011 12:45 AM, Frank Peters wrote: |
3 |
>> Hello, |
4 |
>> |
5 |
>> After banging my head for a while over some strange results, I began |
6 |
>> to suspect GCC-4.5.2, the latest version in portage, was creating |
7 |
>> faulty code. |
8 |
>> |
9 |
>> It seems to a correct suspicion. |
10 |
>> [...] |
11 |
>> int n; |
12 |
>> double x; |
13 |
>> unsigned long int arg; |
14 |
>> unsigned long int *px = (unsigned long int*)&x; |
15 |
> |
16 |
> Your code is buggy, because you're breaking C's aliasing rules. You are |
17 |
> not allowed to use a different pointer type to dereference a variable of |
18 |
> a different type. Doing so results in undefined behavior. |
19 |
|
20 |
And here you can read more thorough information about strict aliasing: |
21 |
|
22 |
http://labs.qt.nokia.com/2011/06/10/type-punning-and-strict-aliasing |