Search code examples
cmacrosparentheses

Why one needs two brackets to use macros in C?


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

What's the reason for doing that?


Solution

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