What does __VA_ARGS__ in a macro mean?

前端 未结 2 527
忘掉有多难
忘掉有多难 2021-02-01 06:16
/* Debugging */
#ifdef DEBUG_THRU_UART0
#   define DEBUG(...)  printString (__VA_ARGS__)
#else
void dummyFunc(void);
#   define DEBUG(...)  dummyFunc()   
#endif
         


        
2条回答
  •  醉话见心
    2021-02-01 07:15

    It's a variadic macro. It means you can call it with any number of arguments. The three ... is similar to the same construct used in a variadic function in C

    That means you can use the macro like this

    DEBUG("foo", "bar", "baz");
    

    Or with any number of arguments.

    The __VA_ARGS__ refers back again to the variable arguments in the macro itself.

    #define DEBUG(...)  printString (__VA_ARGS__)
                   ^                     ^
                   +-----<-refers to ----+
    

    So DEBUG("foo", "bar", "baz"); would be replaced with printString ("foo", "bar", "baz")

提交回复
热议问题