0

There is a piece of code in Linux Device Driver 3rd edition:

#undef PDEBUG
/* undef it, just in case */
#ifdef SCULL_DEBUG
# ifdef __KERNEL__
/* This one if debugging is on, and kernel space */
#
define PDEBUG(fmt, args...) printk( KERN_DEBUG "scull: " fmt, ## args)
# else
/* This one for user space */
#
define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
# endif
#else
# define PDEBUG(fmt, args...) /* not debugging: nothing */
#endif
#undef PDEBUGG
#define PDEBUGG(fmt, args...) /* nothing: it's a placeholder */

I am confused about this code:
Code:

#
define PDEBUG(fmt, args...) printk( KERN_DEBUG "scull: " fmt, ## args)

my problem is, how did this happen? I know the use of "..." in function parameters, whilst I never thought it can be used in macro definitions.
Can anyone explain the grammar behind this?
Thanks in advance.

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by dspjm
1

Well, the specific syntax you posted is a GCC extension. but C99 does support variadic macros with more or less the same syntax as variadic functions. The big difference is how the argument list is retrieved (__VA_ARGS__ for C99 and args for GNU).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.