If sizeof(int) were guaranteed to be sizeof(unsigned int) then maybe a cast could do it: (unsigned int )&a = (unsigned int )&a ^ (unsigned int )&b; (unsigned int )&b = (unsigned int )&a ^ (unsigned int )&b; (unsigned int )&a = (unsigned int )&a ^ (unsigned int )&b;
What would be a general solution? Is there a way to use the preprocessor to spit out sizeof(int) lines that do bitwise xor on every respective byte in a and b?
I'm sure you could do it byte by byte and hope the compiler could optimize it.
(I don't have the C17 spec around, so maybe someone else could check it didn't add that constraint, in which case my response would be "Of course! just use C17!")
I guess that answers your question. You can swap two integers on x86. See the xchg instruction.