liveBook · Manning

Narrow type

As explained in Modern C, Third Edition

A narrow type is a C integer type that undergoes integer promotion before being used in an arithmetic expression.

A narrow type is a C integer type that cannot be used directly in arithmetic. Before an arithmetic expression is evaluated, a narrow integer is promoted to a wider type; on realistic platforms, that type is signed int with the same value, even when the original type was unsigned. section 5.2

The prominent narrow integer types are char and bool. char handles printable characters, while bool holds false and true; C nevertheless treats both as numeric values. The standard constrains, rather than fully specifies, the precision and ranges of the underlying types, so implementations can differ. section 5.2

Table 5.1 Base types according to the four main type classes. Types with a gray background don’t allow for arithmetic; they are promoted before doing arithmetic. Type char is special since it can behave like unsigned or signed, depending on the platform. All types in this table are considered to be distinct types, even if they have the same class and precision.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
ClassSystematic nameOther nameRank
IntegersUnsignedbool_Bool0
unsigned char1
unsigned short2
unsigned intunsigned3
unsigned long4
unsigned long long5
[Un]signedchar1
Signedsigned char1
signed shortshort2
signed intsigned or int3
signed longlong4
signed long longlong long5
Floating pointRealfloat
double
long double
Complexfloat _Complexfloat complex
double _Complexdouble complex
long double _Complexlong double complex

Use the base-type table to identify which C types are narrow and therefore promoted before arithmetic; it also highlights char's platform-dependent signedness. section 5.2

How Modern C, Third Edition covers it

How deep it goes
Defines promotion behavior and implementation variation, but does not provide a worked expression or compiler output.
Examples
Uses char and bool as prominent narrow types and Table 5.1 as a classification reference.
What it assumes
Assumes basic familiarity with C values, types, and arithmetic expressions while introducing narrow-type terminology.
What you can do after
Evaluate arithmetic involving char, bool, and other narrow integers by accounting for promotion to signed int.
How it connects
Connects narrow types with integer promotion, arithmetic expressions, char, bool, and implementation-defined type precision.

Also explained in

Compare how 2 books explain narrow type →

Related concepts

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.