JET*_*ETM 6 c++ c-preprocessor
我的代码中有一行看起来像这样:
#ifndef MACRO(n)
Run Code Online (Sandbox Code Playgroud)
这实际上适用于大多数编译器.但是,这在Solaris上失败,因为官方语法是# ifndef identifier new-line groupopt标识符中不允许使用括号.
检查此宏是否已定义的正确方法是什么?
你不需要(n),如果你使用它,gcc会抱怨:
warning: extra tokens at end of #ifndef directive
Run Code Online (Sandbox Code Playgroud)
这是因为#ifndef预期标识符不是表达式,(n)预处理器可能会忽略它
只需检查宏定义名称就足够了:
#ifndef MACRO
Run Code Online (Sandbox Code Playgroud)