swap macro

Glen Ecklund glen at astroatc.UUCP
Wed Feb 3 05:41:42 AEST 1988


> #define swap(a,b) ((a) = ((b) = ((a) = (a) ^ (b)) ^ (b)) ^ (a))
                                   <1>                       <2>

I'm surprised that nobody has picked the nit that drew my attention.
This macro requires the first assignment, at <1>, to be completed
before the last (a), at <2>, is evaluated.  My reading of K&R says
this cannot be assured.  Or did I miss something?

Glen Ecklund



More information about the Comp.lang.c mailing list