Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why one needs two brackets to use macros in C?

    KdPrint(("Enter HelloWDMAddDevice\n"));

What's the reason for doing that?

like image 294
gdb Avatar asked Dec 04 '22 22:12

gdb


1 Answers

That is so you can pass an entire argument list to the macro and have it pass it on to a function that takes a variable number of arguments.

I would bet anything that the definition of that macro is:

#if DEBUG /* or something like it */
#define KdPrint(args) (printf args)
#else
#define KdPrint(args) /* empty */
#endif

Or similar to some other function that works just like printf.

If it were defined as printf(args), then you could only pass the single string argument, because an argument to a macro can't contain a comma that isn't inside a nested parenthesis.

like image 120
Random832 Avatar answered Dec 22 '22 13:12

Random832