Variable length arg lists for macros

Mark Jones jones at ingr.UUCP
Sat Sep 17 01:56:13 AEST 1988


In article <228 at itivax.UUCP> scs at itivax.UUCP (Steve C. Simmons) writes:
>In article <1036 at cbnews.ATT.COM> lvc at cbnews.ATT.COM (Lawrence V. Cipriani) writes:
>-In article <438 at ucsvc.unimelb.edu.au>, u5565522 at ucsvc.unimelb.edu.au (David Clunie) writes:
>-
>-	#ifdef TRACE
>-	#define trace(anything)	anything
>-	#else
>-	#define trace(anything)
>-	#endif
>-
>	if ( x == m )
>		trace( printf( "the consequences\n) ; )
>	froob( some function ) ;
>
This produced rather different programs depending on the definition of
'trace'!
 
Try rephrasing it as

	if(x == m)
		trace(printf("the consequences\n"));
						   ^
						   ^
						   ^
This will evaluate to:

	if(x == m)
		;
or
	if(x == m)
		printf("the cosequences\n");
				
						  
which will not affect the surrounding code.



More information about the Comp.std.c mailing list