Search code examples
c++c-preprocessorvariadic-macros

What is #__VA_ARGS__ supposed to generate when there are no arguments passed?


Example code:

#define FOO(...) You passed: #__VA_ARGS__
FOO(1,2,3)
FOO()

Preprocess with Visual C++ (version 14 CTP), get:

You passed: "1,2,3"
You passed:

In the last line, #__VA_ARGS__ is turned into nothingness. I would prefer it turned into "".

Is there a definitive reference for what is supposed to happen? I Googled a lot but couldn't find it.

Any suggested work-around would also be useful.


Solution

  • Per 6.10.3.2 The # operator (C11):

    Semantics

    2 - [...] The character string literal corresponding to an empty argument is "". [...]

    So I think MSVC is incorrect here.

    I would workaround this using string literal concatenation:

    #define FOO(...) You passed: "" #__VA_ARGS__