简体   繁体   English

复合文字不是文字吗?

[英]is a compound literal not a literal?

From C in a Nutshell: 来自C in a Nutshell:

Chapter 3 Literals 第3章文字

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. 在C源代码中, 文字是表示固定值的标记,可以是整数,浮点数,字符或字符串。 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. 这里讨论的文字不同于C99标准中引入的复合文字。 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. 有关复合文字的完整描述以及用于创建复合文字的特殊运算符,请参阅第5章。

So a literal has a fixed value, ie its value can't be modified, while a compound literal has modifiable values. 因此,文字具有固定值,即其值不能被修改,而复合文字具有可修改的值。

According to that, which one is correct: 据此,哪一个是正确的:

  • a compound literal is not a literal, or 复合文字不是文字,或
  • the definition of literal should be extended to include a compound literal which becomes the only one exception to the fixed-value rule? 文字的定义应该扩展到包括复合文字,它是固定值规则的唯一例外吗?

Thanks. 谢谢。

The C11 standard never defines "literal" on its own. C11标准从不定义“文字”。 It only speaks of "string literal" and "compound literal" individually. 它只是单独提到“字符串文字”和“复合文字”。

Tokens such as 0 , 0.0 , the A in enum { A } , and '\\0' are called "constants" collectively, and "integer constants", "floating-point constants", "enumeration constants", and "character constants" respectively. 令牌例如00.0时, Aenum { A }'\\0'被称为“常量”统称,和“整数常量”,“浮点常量”,“枚举常数”和“字符常量”分别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM