错误:宏名称必须是使用#ifdef 0的标识符 [英] Error: macro names must be identifiers using #ifdef 0

查看:4630
本文介绍了错误:宏名称必须是使用#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

>

And I get this error


错误:宏名称必须是标识符

error: macro names must be identifiers

是否正在发生?

推荐答案

#ifdef指令用于检查是否定义了预处理器符号。 >标准( C11 6.4.2标识符)要求标识符不能以数字开头:

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的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆