2

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
user1899020
  • 13,167
  • 21
  • 79
  • 154

1 Answers1

3

This is a known bug in msvc

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

a.lasram
  • 4,371
  • 1
  • 16
  • 24