Variable length arg lists for macros
    Chris Torek 
    chris at mimsy.UUCP
       
    Thu Sep 15 23:50:48 AEST 1988
    
    
  
In article <362 at island.uu.net> walker at island.uu.net (Richard Walker)
suggests that
>... macros which expand into code with flow control
>should be formed such that the semicolon cleanly terminates
>the flow, e.g.:
>
>#define COMPLEX_MACRO(foo) (if(SOME_TEST(foo)) {statements;}else)
This works (after correcting the syntax), but I recommend instead
	#define MAC() if (!(normal_test)) /*void*/; else mac_statement
or, if you need {}s,
	#define	MAC() do { mac_statements } while (0)
These have the advantage over the one above that
	MAC()		/* missing semicolon */
	next_stmt;
produces a syntax error, rather than code that reads
	if (some_test) { statements; } else next_stmt;
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris
    
    
More information about the Comp.std.c
mailing list