Re:Too much discussion of the XOR swap trick
by jcalvinowens on Thursday April 16, 2026 @08:27AM
(#47791997)
The "party trick" is more general than just xor, for example:
GCC still sees through it with restrict: https://godbolt.org/z/8n3bGha3e
[ Parent
| on HN ]
Re:Too much discussion of the XOR swap trick
by zahlman on Thursday April 16, 2026 @12:17PM
(#47795649)
This is covered in TFA.
Re:Too much discussion of the XOR swap trick
by sifar on Thursday April 16, 2026 @10:30AM
(#47793518)
This has overflow issues unlike xor.
Re:Too much discussion of the XOR swap trick
by deathanatos on Thursday April 16, 2026 @11:15AM
(#47794427)
Depending on what you think the "issue" is, one of:
* wrapping is well-defined behavior for unsigned integers; signed integer wrapping is UB, but is not used here.
* the equations (that a & b cancel each other out, resulting in the swap) hold even when done in a mod N ring.
Re:Too much discussion of the XOR swap trick
by warmwaffles on Thursday April 16, 2026 @10:31AM
(#47793535)
Yea this is operating on the pointer to the values, but if you use just an `unsigned a` it uses xor