Re: a qusetaion about debug macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sunday 06 May 2007 09:34, Min-Hua Chen wrote:
> hi,
>
> A few days ago, when I was tracing linux driver code. I found some debug
> macros
> like:
>
> #define dbg(fmt, args...) do { printk(KERN_INFO fmt, ## args); } while(0)
> #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ##
> arg)
>
> I checked the C grammar in the appenix of "The C Programming Language,
> 2ed",  and
> the variable-length arg list is like:
>
> parameter-type-list:
>         parameter-list
>         parameter-list, ...
>
> It looks like the "..." must be at the end of arg and there must be a ','
> before it.
>
> And I wrote a little test program:
>
> #define BUG(fmt...) do {printf(fmt);} while (0)
> the fmt is followed by "..." without a ',' before it, but the macro wroked
> well.
>
> I found it is very useful when debugging, but I have no idea why and how
> these macros work. Can someone explain this?
>

The macros are expanded by the preprocessor, thus they have nothing to do with 
the C grammar. 

http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

tavi

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux