Swapping variables using XOR, the edge case
vv
Consider the following function:
void swap(int *a, *b)
{
a* ^= b*; b* ^= a*; a* ^= b*;
}
And it will nicely zero-out x
, if called swap(&x, &x)
, instead of leaving x
intact...
Take care!