#defines with variable # arguments

It takes a clear mind to make it daveb at llama.rtech.UUCP
Tue May 17 14:49:09 AEST 1988


In article <152 at hropus.UUCP> jgy at hropus.UUCP (John Young) writes:
>> >     Are there any versions of cpp which allow one to define macros which
>> > accept variable numbers of arguments?
>I think that some of the AT&T CPLU compilers(cpp's) allow this,
>you just overdeclare the arguments:
>
>#define   Dprintf(a,b,c,d,e,f,g,h,i) {if (Debug) printf(a,b,c,d,e,f,g,h,i);}
>
>and compile.  You will get a warning about each source line which uses
>the wrong number of arguments.

If you do 

#define Dprintf	if(Debug) printf

you don't get any warnings; you do get possible dangling else problems. 
This has rarely been a problem on the occasions I've usedthis technique.

-dB

{amdahl, cpsc6a, mtxinu, sun, hoptoad}!rtech!daveb daveb at rtech.uucp



More information about the Comp.unix.wizards mailing list