Re: What does it mean?

Paul Barton-Davis (pbd@Op.Net)
Tue, 17 Nov 1998 02:03:02 -0500


>Riley Williams wrote:
>> > 4. There is a phased approach to all this that works. Phase 1 would
>> > make all the "printk()" calls macros and enable the compile-out
>> > feature. Everything else would come later.
>>
>> That throws up an interesting question: Is it possible to write a
>> macro that takes a variable number of parameters, like printk() does?

the gcc preprocessor allows:

#define macro(foo, args...)

Here is the version I use in drivers/sound/wavefront.c:

#ifdef WF_DEBUG

/* Thank goodness for gcc's preprocessor ... */

#define DPRINT(cond, format, args...) \
if ((dev.debug & (cond)) == (cond)) { \
printk (KERN_DEBUG LOGNAME format, ## args); \
}
#else
#define DPRINT(cond, format, args...)
#endif

and it works very nicely. i discovered this feature completely
randomly, so i thought i'd just pass it along, in case others are in
the dark. its a very obvious thing to be able to do, and gets rid of
some horrendous macro systems of the past.

--p

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/