문제

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?

도움이 되었습니까?

해결책

This is a known bug in msvc

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top