[Bug c/39121] New: strange behavior of a chain of operations.
nospam at pamies dot cat
gcc-bugzilla@gcc.gnu.org
Fri Feb 6 19:40:00 GMT 2009
#include <stdio.h>
/*
Why the first swap operation works as expected but
it does not happen the same with the second one ?
I guess that it can be due operations within temp values,
but IMHO swap operation should work in both cases.
Thanks !
*/
void swap(int *a, int *b) {
*a ^= *b ^= *a ^= *b;
}
int main() {
int a = 5;
int b = 8;
printf("%d, %d\n", a, b);
a ^= b ^= a ^= b;
printf("%d, %d\n", a, b);
swap(&a, &b);
printf("%d, %d\n", a, b);
}
--
Summary: strange behavior of a chain of operations.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nospam at pamies dot cat
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39121
More information about the Gcc-bugs
mailing list