Re:Swapping two Numbers without Temporary Variables
by tialaramex on Friday March 25, 2022 @05:05AM
(#30799959)
And on a modern CPU the machine code does not map 1-to-1 to what actually happens when this is executed, the phrase "out-of-order execution" ought to give away that even though your machine code says A, then B, then C, the CPU may decide it was better to do A, then C, then B instead.
Express your actual intent, if your chosen language has a "swap" intrinsic, use it, if not write the swap in a natural and idiomatic way, and let other people do the lifting.
Express your actual intent, if your chosen language has a "swap" intrinsic, use it, if not write the swap in a natural and idiomatic way, and let other people do the lifting.