给出以下代码:
void doSomething(int one, int two, int three)
{
//something here
}
#define ONE 1,2,3
#define TWO(arg) doSomething(arg);
#define THREE(arg) TWO(arg)
void doSomethingElse()
{
TWO(ONE)
THREE(ONE)
}
Visual Studio 2010 具有以下预处理器输出(省略一些空行):
void doSomething(int one, int two, int three)
{
}
void doSomethingElse()
{
doSomething(1,2,3);
doSomething(1,2,3);
}
而 gcc 4.2 给出了以下内容:
void doSomething(int one, int two, int three)
{
}
void doSomethingElse()
{
doSomething(1,2,3);
myFile.cpp:17:13: error: macro "TWO" passed 3 arguments, but takes just 1
TWO
}
我不确定哪个是标准的,但我希望它像 Visual Studio 一样工作。有没有办法重构代码以便它在两个编译器中都以这种方式工作?