Search code examples
c++visual-c++c-preprocessorvariadic-macros

is there a way to write macros with a variable argument list in visual C++?


As far as I know, in gcc you can write something like:

#define DBGPRINT(fmt...) printf(fmt);

Is there a way to do that in VC++?


Solution

  • Yes but only since VC++ 2005. The syntax for your example would be:

    #define DBGPRINT(fmt, ...) printf(fmt, __VA_ARGS__)
    

    A full reference is here.