1 |
On 07/01/2011 03:04 AM, Frank Peters wrote: |
2 |
> On Fri, 01 Jul 2011 02:44:36 +0300 |
3 |
> Nikos Chantziaras<realnc@×××××.de> wrote: |
4 |
> |
5 |
>>> |
6 |
>>> Your code is buggy, because you're breaking C's aliasing rules. You are |
7 |
>>> not allowed to use a different pointer type to dereference a variable of |
8 |
>>> a different type. Doing so results in undefined behavior. |
9 |
>> |
10 |
> |
11 |
> Well, the error occurs only within the loop structure. If |
12 |
> I manually "unroll" the loop using the same pointers there |
13 |
> is no error when compiled with "O2." |
14 |
> |
15 |
> IOW, the problem is how the loop is optimized under -O2. |
16 |
|
17 |
When there's "undefined behavior", it really means just that: you cannot |
18 |
make any assumptions about when the result is going to be correct and |
19 |
when not. It might as well depend on whether it was raining yesterday. |