lev.1 code
lev.1 code

Reputation: 87

About integer promotion

According to C17 6.3.1.1

If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int.

Does 'all values' mean whole identifiers in same scope? Then when some identifiers are with variable which can't be represented by int (such as long long int) in same identifier scope, there are no any promotion for identifiers?

Upvotes: 0

Views: 88

Answers (1)

paxdiablo
paxdiablo

Reputation: 882666

Does 'all values' mean whole identifiers in same scope?

I'm not sure why you think all identifiers in a scope matter. The integer promotion applies to a single item, be it an object (e.g., variable) or expression.

What it's saying is that, if every possible value of this item (already one of the types guaranteed to fit into an int or unsigned int as per the paragraphs before your quote(a)) can be represented by the int type, it gets promoted to an int. Otherwise it gets promoted to an unsigned int.


(a) The text states, in full:

The following may be used in an expression wherever an int or unsigned int may be used:

  • An object or expression with an integer type (other than int or unsigned int) whose integer conversion rank is less than or equal to the rank of int and unsigned int.

  • A bit-field of type _Bool, int, signed int, or unsigned int.

If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. All other types are unchanged by the integer promotions.

Upvotes: 2

Related Questions