Cryptic code == Optimized code ? YES : NO ;

Otto J. Makela otto at tukki.jyu.fi
Fri Sep 28 03:18:12 AEST 1990


In article <2514 at cirrusl.UUCP> dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:
   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);

I don't believe this!  I have the chance to correct Mr. Dhesi!

The whole idea of having the do {...} while(0) [sic!] around the macro
definition is to ensure rational behaviour of the macro (which to the
unaided eye looks a lot like a function call) if invoked inside an
if-then-else type structure, where adding an extra ';' could affect the
syntactic interpretatiton.  Thus, you DON'T use a ';' at the end of the
macro.

Actually, typeof() is not only proposed, it is implemented in gcc.
--
   /* * * Otto J. Makela <otto at jyu.fi> * * * * * * * * * * * * * * * * * * */
  /* Phone: +358 41 613 847, BBS: +358 41 211 562 (CCITT, Bell 24/12/300) */
 /* Mail: Kauppakatu 1 B 18, SF-40100 Jyvaskyla, Finland, EUROPE         */
/* * * Computers Rule 01001111 01001011 * * * * * * * * * * * * * * * * */



More information about the Comp.lang.c mailing list