gpt4 book ai didi

c - 宏名称的有效字符是什么?

转载 作者:太空狗 更新时间:2023-10-29 16:20:17 28 4
gpt4 key购买 nike

C 风格的宏名称是否遵循与标识符相同的命名规则?编译器升级后,它现在对遗留应用程序发出此警告:

warning #3649-D: white space is required between the macro name "CHAR_" and its replacement text
#define CHAR_& 38

这行代码定义了一个 & 符号的 ASCII 值常量。

#define   DOL_SN        36
#define PERCENT 37
#define CHAR_& 38
#define RT_SING 39
#define LF_PAR 40

我假设这个定义(据我所知,实际上没有被任何代码引用)是错误的,应该更改为类似“CHAR_AMPERSAND”的定义?

最佳答案

宏名称只能由字母数字字符和下划线组成,即 'a-z''A-Z''0-9''_',第一个字符不能是数字。一些预处理器也允许美元符号字符 '$',但你不应该使用它;不幸的是,我无法引用 C 标准,因为我没有它的副本。

来自GCC documentation :

Preprocessing tokens fall into five broad classes: identifiers, preprocessing numbers, string literals, punctuators, and other. An identifier is the same as an identifier in C: any sequence of letters, digits, or underscores, which begins with a letter or underscore. Keywords of C have no significance to the preprocessor; they are ordinary identifiers. You can define a macro whose name is a keyword, for instance. The only identifier which can be considered a preprocessing keyword is defined. See Defined.

This is mostly true of other languages which use the C preprocessor. However, a few of the keywords of C++ are significant even in the preprocessor. See C++ Named Operators.

In the 1999 C standard, identifiers may contain letters which are not part of the “basic source character set”, at the implementation's discretion (such as accented Latin letters, Greek letters, or Chinese ideograms). This may be done with an extended character set, or the '\u' and '\U' escape sequences. The implementation of this feature in GCC is experimental; such characters are only accepted in the '\u' and '\U' forms and only if -fextended-identifiers is used.

As an extension, GCC treats '$' as a letter. This is for compatibility with some systems, such as VMS, where '$' is commonly used in system-defined function and object names. '$' is not a letter in strictly conforming mode, or if you specify the -$ option. See Invocation.

关于c - 宏名称的有效字符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/369495/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com