1

From the standard draft N1256, section 6.4.4.1, clause 5:

The type of an integer constant is the first of the corresponding list in which its value can be represented.

From the table, it seems that octal and hexadecimal constants without suffixes will be assigned any standard integer type (the smallest suitable combination of signed/unsigned and int/long int/long long int). For decimal constants, only the signed types will be considered by default.

It makes sense to me why u/U exist; signed overflow behaviour is different from unsigned overflow behaviour at best, and UB at worst, so I guess it may be necessary to specify the unsignedness of a literal in complicated expressions.

This leaves us with the L/l and LL/ll suffixes. They can only be used to select the lower bound of the type of integer literals. What practical purpose does that serve in C99?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
  • To make a small value be in a large type? Ex. 0 as long long. Maybe doesn't answer your question, but is example. – ABuckau Aug 10 '16 at 11:31
  • @ABuckau That's indeed an example of what it does. But when you use it in an expression with different integer types of equal signedness, such values will be converted to a common type (section 6.3.1.8, clause 1 for more precise wording). Something similar happens when you use it as an initialiser, or on the right hand side of a simple assignment. I still don't see why you'd *need* it. –  Aug 10 '16 at 12:05
  • Compare `~0ull` and `~0`. – Mats Aug 10 '16 at 12:36
  • @Mats That's a decent example of where the difference matters, but it's not clear to me why you'd want to write `~0ull` instead of the much more descriptive `ULLONG_MAX` (which is the exact same thing). –  Aug 10 '16 at 14:12
  • 6
    This seems to have been asked before: http://stackoverflow.com/questions/13134956/ – Mats Aug 10 '16 at 14:38
  • There are a number of instances where they are required or provide clarity in bitwise operations, etc. – David C. Rankin Aug 13 '16 at 09:19

0 Answers0