GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 27233 - incorrect xor result on arrays
Summary: incorrect xor result on arrays
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-21 00:38 UTC by Raphael H Ribas
Modified: 2006-04-21 01:03 UTC (History)
48 users (show)

See Also:
Host: x86 linux
Target:
Build: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raphael H Ribas 2006-04-21 00:38:40 UTC
the following code

#include <stdio.h>

int main() {
    int a[1],b[1];
    a[0]=5;
    b[0]=7;
    a[0]^=b[0]^=a[0]^=b[0];
    printf("%d %d\n",a[0],b[0]);
    return 0;
}

this should produce "7 5" as outpout but it produces "0 5"
Comment 1 Andrew Pinski 2006-04-21 00:40:19 UTC
a[0]^=b[0]^=a[0]^=b[0];

That is undefined, you are modifing a[0] and b[0] more than once without a sequence point.

*** This bug has been marked as a duplicate of 11751 ***
Comment 2 Raphael H Ribas 2006-04-21 01:01:18 UTC
int main() {
    int a,b;
    a=5;
    b=7;
    a^=b^=a^=b;
    printf("%d %d\n",a,b);
    return 0;
}

than why this one produces expected answer?
Comment 3 Andrew Pinski 2006-04-21 01:03:55 UTC
(In reply to comment #2)
> than why this one produces expected answer?

As I said it is undefined so it could produce your expected result or it does not have to.  But the example in comment #2 is also undefined for the same reason, it is just you get a different result but there is no one correct result here really.