简而言之,来自 C:
Chapter 3 Literals
In C source code, a literal is a token that denotes a fixed value, which may be an integer, a floating-point number, a character, or a string. A literal’s type is determined by its value and its notation.
The literals discussed here are different from compound literals, which were introduced in the C99 standard. Compound literals are ordinary modifiable objects, similar to variables. For a full description of compound literals and the special operator used to create them, see Chapter 5.
因此字面量具有固定值,即它的值不能被修改,而复合字面量具有可修改的值。
据此,哪一个是正确的:
- 复合文字不是文字,或者
- 字面量的定义应该扩展到包含复合字面量,它成为固定值规则的唯一异常(exception)?
谢谢。
最佳答案
C11 标准从不单独定义“文字”。它只单独谈到“字符串文字”和“复合文字”。
0
、0.0
、enum { A }
中的 A
和 '\0'
统称为“常量”,分别称为“整数常量”、“ float 常量”、“枚举常量”、“字符常量”。
关于c - 复合文字不是文字吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45684377/