4 ms·
That's an old trick that, IMHO, makes no practical sense at all. Unless you are in tight long running loop that needs to swaps several pair of values, the advan
by notorandit 5y ago
That's an old trick that, IMHO, makes no practical sense at all.
Unless you are in tight long running loop that needs to swaps several pair of values, the advantage of the trick is rather tiny with the extra disadvantage of portability and readability.
Watch your steps! The swap with floats relies on sizeof( float ) == sizeof( int ) which could not always be the case.
Yes, you can create a set of macros and conditional compilation stanzas to cope with that and cover also char, short, long, long long, double and long double.
Finally, the explanation on why it works would be a great supplement to the article.
- Brian_K_White 5y agoAnd as far as I can see the assert() should have been if(x==y) return(0).