Cryptic code == Optimized code ? YES : NO ;

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Thu Sep 27 13:32:16 AEST 1990


The real advantage of the exclusive OR method of exchanging two
variables is that you can make it into a macro in C.  It's a little
harder to do that with the temp variable method because it is currently
impossible to declare a variable in C without first knowing its type.
The real question is whether the swap macro using exclusive OR is
faster than a swap() function.

I have seen a "typeof" keyword proposed that would fix this deficieny:

#define swap(a,b)  do { typeof(a) tmp; tmp = a;  a = b; b = tmp; } until (0);
--
Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.lang.c mailing list