碼:
#include
using namespace std;
#define ADD(x,y) ((x)+(y))
int main( int argc, char** argv )
{
cout << ADD(1,2,) << endl;
return 0;
}
編譯器輸出:
1>Compiling…
1>main.cpp
1>c:\warn_test\main.cpp(9) : warning C4002: too many actual parameters for macro ‘ADD’
為什么這不是錯誤?
g(GCC)4.2.1 20070719 [FreeBSD]給出了更合理的(在我看來)輸出:
main.cpp:9:18: error: macro “ADD” passed 3 arguments, but takes just 2
main.cpp: In function ‘int main(int, char**)’:
main.cpp:9: error: ‘ADD’ was not declared in this scope
雖然我不完全確定編譯器認為第三個參數是什么.
編輯:添加完整的gcc輸出和版本信息.