简体   繁体   中英

is a compound literal not a literal?

From C in a Nutshell:

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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