user1899020
user1899020

Reputation: 13575

Variadic Macros need a unmeaningful macro to let it work?

The following code is okay on VC++ 2012

#include <algorithm>    

#define MAX_OF_2(a,b)    std::max(a,b)
#define FOO(a)           a 

// work
#define MAX2(...)        FOO(MAX_OF_2(__VA_ARGS__)) 

// Not work
// #define MAX2(...)        MAX_OF_2(__VA_ARGS__)

int main()
{
    int i = MAX2(1,2);
}

It cannot compile without using FOO macro. It shows not engough actual parameter for MAX_OF_2. Why or any bug on compiler?

Upvotes: 2

Views: 84

Answers (1)

a.lasram
a.lasram

Reputation: 4411

This is a known bug in msvc

In your case __VA_ARGS__ is considered as if it's a macro that needs expansion.

Upvotes: 3

Related Questions