Error: macro names must be identifiers using #ifdef 0(错误:宏名称必须是使用 #ifdef 0 的标识符)
问题描述
我有一个用 C++ 编写的应用程序的源代码,我只想用以下方式评论一些东西:
I have the source code of an application written in C++ and I just want to comment something using:
#ifdef 0
...
#endif
我得到了这个错误
错误:宏名必须是标识符
error: macro names must be identifiers
为什么会这样?
推荐答案
#ifdef 指令用于检查是否定义了预处理器符号. 标准(C11 6.4.2 Identifiers) 规定标识符不得以数字开头:
The #ifdef directive is used to check if a preprocessor symbol is defined. The standard (C11 6.4.2 Identifiers) mandates that identifiers must not start with a digit:
identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit
identifier-nondigit:
nondigit
universal-character-name
other implementation-defined characters>
nondigit: one of
_ a b c d e f g h i j k l m
n o p q r s t u v w x y z
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
digit: one of
0 1 2 3 4 5 6 7 8 9
使用预处理器阻塞代码的正确形式是:
The correct form for using the pre-processor to block out code is:
#if 0
: : :
#endif
你也可以使用:
#ifdef NO_CHANCE_THAT_THIS_SYMBOL_WILL_EVER_EXIST
: : :
#endif
但您需要确信这些符号不会被您自己的代码以外的代码无意中设置.换句话说,不要使用其他人也可能使用的 NOTUSED 或 DONOTCOMPILE 之类的东西.为了安全起见,应该首选 #if 选项.
but you need to be confident that the symbols will not be inadvertently set by code other than your own. In other words, don't use something like NOTUSED or DONOTCOMPILE which others may also use. To be safe, the #if option should be preferred.
这篇关于错误:宏名称必须是使用 #ifdef 0 的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误:宏名称必须是使用 #ifdef 0 的标识符
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
