SWAP macro

Paul Schauble Schauble at MIT-MULTICS.ARPA
Mon Jun 23 14:25:34 AEST 1986


I've gotten lots of respones to my request for a form of the macro that
would make
  swap(*a++, *b++);
 work.  Almost all of them missed the point.  The swap requires a
temporary.  Generating that temporary requires knowing the type.
Several of the solutions would work fine if *a and *b were int's, but I
never said that.

Recall the my original message was posted as a justification for a
typeof macro, akin to sizeof.  I find that the need to generate
temporaries in a macro is not uncommon.  Unless one is willing to do a
different version of the macro for each type, you need a way to generate
a new variable of the same type as one of the macro args.  The language
provides no way to do this.



More information about the Comp.lang.c mailing list