[linux-elitists] Stupid C tricks

Jason Spence jspence@lightconsulting.com
Fri Aug 27 22:14:43 PDT 2004

On Fri, Aug 27, 2004 at 09:56:51PM -0700, Greg KH wrote: 
> Ick, what about something like what the kernel does in places:
> #ifdef DEBUG
> #define dbg(format, arg...) printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , ## arg)
> #else
> #define dbg(format, arg...) do {} while (0)
> #endif
> Put __LINE__ in there too and you are good to go.  Variable length
> arguments with a macro, fun stuff (don't mess with the spaces in that
> definition, older versions of gcc are very picky...)

The problem is that the trick relies on support for variable arguments
in macros, something MS C doesn't support.  Older versions of
HP/Compaq/DEC C don't support it either, although it turns out the
recent versions do:


Hmm, this is interesting: apparently MS C is the only compiler without
variable argument macro support.  Open Watcom 1.2, Intel C, Digital
Mars, and my other favorite compilers support C99 macros just fine (I
just checked).  I was under the impression this was a not so supported
C99 thing that I couldn't rely on being available.  In light of the
fact that Intel C (which I prefer over MS C anyway, when I can get
licenses for it) supports it, I think I just found a reason to finally
ditch MS C.

 - Jason                                                 Last known location: 

We can predict everything, except the future.

More information about the linux-elitists mailing list