Commas in macro arguments

jeff jeff at samna.UUCP
Thu Mar 29 07:26:59 AEST 1990


In article <T9H20-9ggpc2 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
>> >#define call(a,b)	a(b)
>
>> >I can use that to call a function with one argument. How can I use
>> >it to call a function with two arguments?
>
>Sometimes you can, depending on how much you want to munge the arguments:
>
>#define call(a,b) a b
>
>call(a,(b))
>call(c,(d,e))

I sometimes use this mechanism to put debugging printf's in source
files (Can be used for any variable argument macro).

Debugging statements are written like this:

	DPRINTF(("Variable x=%d, y=%d, z=%d\n", x, y, z));


Then in a header file:

#ifdef	DEBUG
#	define	DPRINTF(s) printf s
#else
#	define	DPRINTF(s)
#endif


Sometimes it's kinda hard to remember the extra set of parentheses, but...

Jeff



More information about the Comp.lang.c mailing list