liveBook · Manning

Effective value

As explained in Modern C, Third Edition

An effective value is the value actually represented by a literal after the language's conversion and rounding rules are applied.

An effective value is the value a literal contributes after its spelling, base, suffix, type, and required conversions are taken into account. For example, int x = 0xFFFF'FFFF; does not guarantee that x receives −1: the literal's effective value is +4,294,967,295, and conversion to a signed value is not universally guaranteed. section 5.3

TAKEAWAY rules:

  • Use decimal literals for negative values; do not rely on binary, octal, or hexadecimal spellings to represent negative values. section 5.3
  • Treat the base prefix as significant: it determines how the literal is read and can influence its deduced type. section 5.3
  • Use suffixes deliberately: U forces unsigned, L requests at least long, LL requests long long, and WB selects a bit-precise type in C23. section 5.3
Table 5.3 Examples for literals and their types, under the supposition that signed and unsigned have the commonly used representation with 32 bits
Literal 𝑥 Value Type Value of -𝑥
2'147'483'647 +2,147,483,647 signed -2,147,483,647
2'147'483'648 +2,147,483,648 signed long -2,147,483,648
4'294'967'295 +4,294,967,295 signed long -4,294,967,295
0x7FFF'FFFF +2,147,483,647 signed -2,147,483,647
0x8000'0000 +2,147,483,648 unsigned +2,147,483,648
0xFFFF'FFFF +4,294,967,295 unsigned +1
1 +1 signed -1
1U +1 unsigned +4,294,967,295

Compare literal spellings with their effective values, types, and negated results under a commonly used 32-bit representation. section 5.3

Table 5.4 Suffixes for integer literals and their types
Suffix Type
l   or  L At least long
ll or  LL long long
wb or  WB _BitInt(𝑁) for sufficiently large 𝑁
u   or  U Force unsigned

Use the suffix table to check how spelling changes an integer literal's type or signedness. section 5.3

How Modern C, Third Edition covers it

How deep it goes
Works through integer literal values, types, and conversions, but does not develop a general account of floating-point rounding.
Examples
Uses negative decimal literals, hexadecimal boundary values, suffixed literals such as 1U and 1ULL, and comparative tables.
What you can do after
Evaluate integer literal values and types, choose safer negative-literal spellings, and avoid relying on nonportable signed conversions.
How it connects
Connects literal bases and suffixes with integer types, signedness, representations, and conversions.

Also explained in

Compare how 2 books explain effective value →

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.