c - C 预处理器/宏中的无效字符?

标签 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/

相关文章:

c - C 预处理器如何处理循环依赖?

c - 有没有办法编写一个知道另一个宏被使用了多少次的宏?

c - 如何将 IEEE 754 单精度二进制 float 转换为十进制数?

c - 非 GTK 应用程序中的 GTK+3 文件选择器

c - 某些配置中不需要的 C 类型的良好实践

c - 使用 gcc 获取二进制文件中不带路径的文件名

c++ - 重置 C/C++ 预处理器 #line 物理文件/行

c - 损坏的二分搜索和冒泡排序

c - 如何使用 Clang 从源代码中提取控制流图?

c - 静态链接 LAPACK