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.

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).

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.