سؤال

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