------- Comment #2 from nospam at pamies dot cat  2009-02-06 21:07 -------
Is not the same bug as #15145. I agree with you that there is just one sequence
point, but the operation is not undefined.

void swap(int *a, int *b) {
    *a ^= *b ^= *a ^= *b;
}

This code should be compiled to:

*a = *a ^ *b;
*b = *b ^ *a;
*a = *a ^ *b;

And not to something like (I think that is what happens):

int tmp;
tmp = *a ^ *b;
*b = *b ^ tmp;
//On that point *a should contain 5^8 instead of the original value 5.
//This happens because the temp variable generated by the compiler.
*a = *a ^ *b;  

I think that the compiler is not translating properly what was written in the
source code. Summarizing, I think that in:

y = 1;
x = (y += 1);

The execution order should be:

volatile_register <--- y + 1
y                 <--- volatile_register
x                 <--- volatile_register

instead of:

volatile_register <--- y + 1
x                 <--- volatile_register
y                 <--- volatile_register


-- 

nospam at pamies dot cat changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39121

Reply via email to