Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!ibmchs!auschs!awdprime!sanders.austin.ibm.com!sanders From: sanders@peyote.cactus.org (Tony Sanders) Newsgroups: comp.lang.c Subject: Re: Passing Variable Numbers of Arguments Message-ID: <5270@awdprime.UUCP> Date: 12 Feb 91 01:52:52 GMT References: <5196@media-lab.MEDIA.MIT.EDU> <1991Feb11.225815.5875@zoo.toronto.edu> Sender: news@awdprime.UUCP Reply-To: sanders@peyote.cactus.org (Tony Sanders) Organization: IBM AWD, Austin Lines: 38 Originator: sanders@sanders.austin.ibm.com In article <1991Feb11.225815.5875@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >For a function, you'll need to use (ANSI C) or (many >old implementations). Can't be done with a macro at all. This is annoying. How do get around this problem so I can easily eliminate debug code if NODEBUG is set (or if DEBUG isn't set, whichever). For instance... This works great: #ifdef NODEBUG #define DPV(var,type) /* Removes code like magic */ #else #define DPV(var,type) fprintf(stderr,"%s:%d, " # var " = %" # type "\n",var); #endif But I can't do this: #ifdef NODEBUG #define DP(fmt,...) /* sigh */ #else #define DP(fmt,...) fprintf(stderr,fmt,...); #endif So I do this: #ifdef NODEBUG #define DP(level) if (0) /* I hope the optimizer gets rid of this */ #else extern DebugPrint(char *,...); #define DP(level) if (debug&level) DebugPrint #endif DP(1)("this fmt string %s\n","sucks rocks"); Any better ideas??? -- sanders@peyote.cactus.org First rule of software: Throw the first one away. and so on... I am not an IBM representative and I speak only for myself.