<分区>
我不允许在宏中使用哪些不同的无效字符?
看来 #define TE$T 8
正在工作,所以 $
是有效的。
有人有无效字符列表吗? (或者相反,有效列表)。
标签 c c-preprocessor
<分区>
我不允许在宏中使用哪些不同的无效字符?
看来 #define TE$T 8
正在工作,所以 $
是有效的。
有人有无效字符列表吗? (或者相反,有效列表)。
最佳答案
是您的编译器允许使用 $
作为标识符。它不是标准的,如果你使用 -pedantic
或类似的编译器,你不应该期望其他编译器提供它或你的编译器允许它。
在 C11 草案的通用扩展附录中:
J.5.2 Specialized identifiers
1 Characters other than the underscore _, letters, and digits, that are not part of the basic source character set (such as the dollar sign $, or characters in national character sets) may appear in an identifier (6.4.2).
第 6.4.2 节显示了哪些字符每个符合标准的编译器必须 支持:
6.4.2 Identifiers
6.4.2.1 General
Syntax 1 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
您应该将自己限制在这些范围内。
关于c - C 预处理器/宏中的无效字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37568161/