of the object until execution of the program leaves the scope of the declaration[38] . If the scope is
entered recursively, a new instance of the object is created each time. The initial representation of
the object is indeterminate.
Footnote 38) Leaving the innermost block containing the declaration, or jumping to a point in that block or an embedded block prior
to the declaration, leaves the scope of the declaration.
8 A non-lvalue expression with structure or union type, where the structure or union contains a
member with array type (including, recursively, members of all contained structures and unions)
refers to an object with automatic storage duration and temporary lifetime.[39] Its lifetime begins
when the expression is evaluated and its initial value is the value of the expression. Its lifetime ends
when the evaluation of the containing full expression ends. Any attempt to modify an object with
temporary lifetime results in undefined behavior. An object with temporary lifetime behaves as if it
were declared with the type of its value for the purposes of effective type. Such an object need not
have a unique address.
Forward references: array declarators (<IP_ADDRESS>), compound literals (<IP_ADDRESS>), declarators (6.7.6),
function calls (<IP_ADDRESS>), initialization (6.7.10), statements (6.8), effective type (6.5).
Footnote 39) The address of such an object is taken implicitly when an array member is accessed.
6.2.5 [Types]
1 The meaning of a value stored in an object or returned by a function is determined by the type of the
expression used to access it. (An identifier declared to be an object is the simplest such expression;
the type is specified in the declaration of the identifier.) Types are partitioned into object types (types
that describe objects) and function types (types that describe functions). At various points within a
translation unit an object type may be incomplete[40] (lacking sufficient information to determine the
size of objects of that type) or complete (having sufficient information)41) .
Footnote 40) An incomplete type can only be used when the size of an object of that type is not needed. It is not needed, for example,
when a typedef name is declared to be a specifier for a structure or union, or when a pointer to or a function returning a
structure or union is being declared. The specification has to be complete before such a function is called or defined.
2 An object declared as type bool is large enough to store the values false and true.
3 An object declared as type char is large enough to store any member of the basic execution char-
acter set. If a member of the basic execution character set is stored in a char object, its value is
guaranteed to be nonnegative. If any other character is stored in a char object, the resulting value is
implementation-defined but shall be within the range of values that can be represented in that type.
4 There are five standard signed integer types, designated as signed char, short int, int, long int,
and long long int. (These and other types may be designated in several additional ways, as
described in 6.7.2.)
5 A bit-precise signed integer type is designated as _BitInt( N) where N is an integer constant expression
that specifies the number of bits that are used to represent the type, including the sign bit. Each
value of N designates a distinct type[42] . There may also be implementation-defined extended signed
integer types [43] . The standard signed integer types, bit-precise signed integer types, and extended
signed integer types are collectively called signed integer types. [44]
Footnote 42) Thus, _BitInt(3) is not the same type as _BitInt(4) .
Footnote 43) Implementation-defined keywords have the form of an identifier reserved for any use as described in 7.1.3.
Footnote 44) Any statement in this document about signed integer types also applies to the bit-precise signed integer types and the
extended signed integer types, unless otherwise noted.
6 An object declared as type signed char occupies the same amount of storage as a "plain" char
object. A "plain" int object has the natural size suggested by the architecture of the execution
environment (large enough to contain any value in the range INT_MIN to INT_MAX as defined in the
header <limits.h>).
7 For each of the signed integer types, there is a corresponding (but different) unsigned integer type
(designated with the keyword unsigned) that uses the same amount of storage (including sign
information) and has the same alignment requirements. The type bool and the unsigned integer
types that correspond to the standard signed integer types are the standard unsigned integer types. The
unsigned integer types that correspond to the extended signed integer types are the extended unsigned
integer types. The unsigned integer types that correspond to the bit-precise signed integer types
are the bit-precise unsigned integer types. The standard unsigned integer types, bit-precise unsigned
integer types, and extended unsigned integer types are collectively called unsigned integer types.[45]
Footnote 45) Any statement in this document about unsigned integer types also applies to the bit-precise unsigned integer types and
the extended unsigned integer types, unless otherwise specified.
8 The standard signed integer types and standard unsigned integer types are collectively called the
standard integer types; the bit-precise signed integer types and bit-precise unsigned integer types
are collectively called the bit-precise integer types the extended signed integer types and extended
unsigned integer types are collectively called the extended integer types.
9 For any two integer types with the same signedness and different integer conversion rank (see
<IP_ADDRESS>), the range of values of the type with smaller integer conversion rank is a subrange of the
values of the other type.
10 The range of nonnegative values of a signed integer type is a subrange of the corresponding unsigned
integer type, and the representation of the same value in each type is the same.[46] The range of
representable values for the unsigned type is 0 to 2N − 1 (inclusive). A computation involving
unsigned operands can never produce an overflow, because arithmetic for the unsigned type is
performed modulo 2N .
Footnote 46) The same representation and alignment requirements are meant to imply interchangeability as arguments to functions,
return values from functions, and members of unions.
11 There are three standard floating types, designated as float, double, and long double. [47] The set
of values of the type float is a subset of the set of values of the type double; the set of values of the
type double is a subset of the set of values of the type long double.
Footnote 47) See "future language directions" (6.11.1).
12 There are three decimal floating types, designated as _Decimal32 , _Decimal64 , and _Decimal128 .
Respectively, they have the IEC 60559 formats: decimal32,[48] decimal64, and decimal128. Decimal
floating types are real floating types.
Footnote 48) IEC 60559 specifies decimal32 as a data-interchange format that does not require arithmetic support; however,
_Decimal32 is a fully supported arithmetic type.
13 The standard floating types and the decimal floating types are collectively called the real floating
types.
14 There are three complex types, designated as float _Complex, double _Complex, and long double
_Complex .[49] (Complex types are a conditional feature that implementations need not support; see
<IP_ADDRESS>.) The real floating and complex types are collectively called the floating types.
Footnote 49) A specification for imaginary types is in Annex G.
15 For each floating type there is a corresponding real type, which is always a real floating type. For real
floating types, it is the same type. For complex types, it is the type given by deleting the keyword
_Complex from the type name.
16 Each complex type has the same representation and alignment requirements as an array type
containing exactly two elements of the corresponding real type; the first element is equal to the real
part, and the second element to the imaginary part, of the complex number.
17 The type char, the signed and unsigned integer types, and the floating types are collectively called
the basic types. The basic types are complete object types. Even if the implementation defines two or
more basic types to have the same representation, they are nevertheless different types.[50]
Footnote 50) An implementation can define new keywords that provide alternative ways to designate a basic (or any other) type; this
18 The three types char, signed char, and unsigned char are collectively called the character types.
The implementation shall define char to have the same range, representation, and behavior as either
signed char or unsigned char.[51]
Footnote 51) CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be used to distinguish the
two options. Irrespective of the choice made, char is a separate type from the other two and is not compatible with either.
19 An enumeration comprises a set of named integer constant values. Each distinct enumeration
constitutes a different enumerated type.
20 The type char, the signed and unsigned integer types, and the enumerated types are collectively
called integer types. The integer and real floating types are collectively called real types.
21 Integer and floating types are collectively called arithmetic types. Each arithmetic type belongs to
one type domain: the real type domain comprises the real types, the complex type domain comprises the
complex types.
22 The void type comprises an empty set of values; it is an incomplete object type that cannot be
completed.
23 Any number of derived types can be constructed from the object and function types, as follows:
— An array type describes a contiguously allocated nonempty set of objects with a particular
member object type, called the element type. The element type shall be complete whenever the
array type is specified. Array types are characterized by their element type and by the number
of elements in the array. An array type is said to be derived from its element type, and if its
element type is T, the array type is sometimes called "array of T". The construction of an array
type from an element type is called "array type derivation".
— A structure type describes a sequentially allocated nonempty set of member objects (and, in
certain circumstances, an incomplete array), each of which has an optionally specified name
and possibly distinct type.
— A union type describes an overlapping nonempty set of member objects, each of which has an
optionally specified name and possibly distinct type.
— A function type describes a function with specified return type. A function type is characterized
by its return type and the number and types of its parameters. A function type is said to
be derived from its return type, and if its return type is T, the function type is sometimes
called "function returning T". The construction of a function type from a return type is called
"function type derivation".
— A pointer type may be derived from a function type or an object type, called the referenced type. A
pointer type describes an object whose value provides a reference to an entity of the referenced
type. A pointer type derived from the referenced type T is sometimes called "pointer to T".
The construction of a pointer type from a referenced type is called "pointer type derivation".
A pointer type is a complete object type.
— An atomic type describes the type designated by the construct _Atomic (type-name). (Atomic
types are a conditional feature that implementations need not support; see <IP_ADDRESS>.)
These methods of constructing derived types can be applied recursively.
24 Arithmetic types, pointer types, and the nullptr_t type are collectively called scalar types. Array
and structure types are collectively called aggregate types[52] .
Footnote 52) Note that aggregate type does not include union type because an object with union type can only contain one member at
a time.
25 An array type of unknown size is an incomplete type. It is completed, for an identifier of that type,
by specifying the size in a later declaration (with internal or external linkage). A structure or union
type of unknown content (as described in <IP_ADDRESS>) is an incomplete type. It is completed, for all
does not violate the requirement that all basic types be different. Implementation-defined keywords have the form of an
identifier reserved for any use as described in 7.1.3.
declarations of that type, by declaring the same structure or union tag with its defining content later
in the same scope.
26 A complete type shall have a size that is less than or equal to SIZE_MAX. A type has known constant
size if it is complete and is not a variable length array type.
27 Array, function, and pointer types are collectively called derived declarator types. A declarator type
derivation from a type T is the construction of a derived declarator type from T by the application of
an array-type, a function-type, or a pointer-type derivation to T.
28 A type is characterized by its type category, which is either the outermost derivation of a derived
type (as noted above in the construction of derived types), or the type itself if the type consists of no
derived types.
29 Any type so far mentioned is an unqualified type. Each unqualified type has several qualified versions
of its type[53] , corresponding to the combinations of one, two, or all three of the const, volatile, and
restrict qualifiers. The qualified or unqualified versions of a type are distinct types that belong to
the same type category and have the same representation and alignment requirements.[54] An array
and its element type are always considered to be identically qualified[55] . Any other derived type is
not qualified by the qualifiers (if any) of the type from which it is derived.
Footnote 53) See 6.7.3 regarding qualified array and function types.
Footnote 54) The same representation and alignment requirements are meant to imply interchangeability as arguments to functions,
return values from functions, and members of unions.
Footnote 55) This does not apply to the _Atomic qualifier. Note that qualifiers do not have any direct effect on the array type itself,
but affect conversion rules for pointer types that reference an array type.
30 Further, there is the _Atomic qualifier. The presence of the _Atomic qualifier designates an atomic
type. The size, representation, and alignment of an atomic type need not be the same as those of
the corresponding unqualified type. Therefore, this document explicitly uses the phrase "atomic,
qualified, or unqualified type" whenever the atomic version of a type is permitted along with the
other qualified versions of a type. The phrase "qualified or unqualified type", without specific
mention of atomic, does not include the atomic types.
31 A pointer to void shall have the same representation and alignment requirements as a pointer to a
character type.[54] Similarly, pointers to qualified or unqualified versions of compatible types shall
have the same representation and alignment requirements. All pointers to structure types shall have
the same representation and alignment requirements as each other. All pointers to union types shall
have the same representation and alignment requirements as each other. Pointers to other types
need not have the same representation or alignment requirements.
Footnote 54) The same representation and alignment requirements are meant to imply interchangeability as arguments to functions,
return values from functions, and members of unions.
32 EXAMPLE 1 The type designated as "float *" has type "pointer to float". Its type category is pointer, not a floating type.
The const-qualified version of this type is designated as "float * const" whereas the type designated as "const float *"
is not a qualified type — its type is "pointer to const-qualified float" and is a pointer to a qualified type.
33 EXAMPLE 2 The type designated as "struct tag (*[5])(float)" has type "array of pointer to function returning
struct tag". The array has length five and the function has a single parameter of type float. Its type category is array.
Forward references: compatible type and composite type (6.2.7), declarations (6.7).
6.2.6 [Representations of types]
<IP_ADDRESS> [General]
1 The representations of all types are unspecified except as stated in this subclause.
2 Except for bit-fields, objects are composed of contiguous sequences of one or more bytes, the number,
order, and encoding of which are either explicitly specified or implementation-defined.
3 Values stored in unsigned bit-fields and objects of type unsigned char shall be represented using a
pure binary notation.[56]
Footnote 56) A positional representation for integers that uses the binary digits 0 and 1, in which the values represented by successive
bits are additive, begin with 1, and are multiplied by successive integral powers of 2, except perhaps the bit with the highest
position. (Adapted from the American National Dictionary for Information Processing Systems.) A byte contains CHAR_BIT bits,
_
and the values of type unsigned char range from 0 to 2CHAR BIT − 1.
4 Values stored in non-bit-field objects of any other object type are represented using n× CHAR_BIT bits,
where n is the size of an object of that type, in bytes. An object that has the value may be copied into
an object of type unsigned char [n] (e.g., by memcpy); the resulting set of bytes is called the object
representation of the value. Values stored in bit-fields consist of m bits, where m is the size specified
for the bit-field. The object representation is the set of m bits the bit-field comprises in the addressable
storage unit holding it. Two values (other than NaNs) with the same object representation compare
equal, but values that compare equal may have different object representations.
5 Certain object representations need not represent a value of the object type. If such a representation
is read by an lvalue expression that does not have character type, the behavior is undefined. If such
a representation is produced by a side effect that modifies all or any part of the object by an lvalue
expression that does not have character type, the behavior is undefined[57] . Such a representation is
called a non-value representation.
Footnote 57) Thus, an automatic variable can be initialized to a non-value representation without causing undefined behavior, but the
value of the variable cannot be used until a proper value is stored in it.
6 When a value is stored in an object of structure or union type, including in a member object, the bytes
of the object representation that correspond to any padding bytes take unspecified values[58] . The
object representation of a structure or union object is never a non-value representation, even though
the byte range corresponding to a member of the structure or union object may be a non-value
representation for that member.
Footnote 58) Thus, for example, structure assignment need not copy any padding bits.
7 When a value is stored in a member of an object of union type, the bytes of the object representation
that do not correspond to that member but do correspond to other members take unspecified values.
8 Where an operator is applied to a value that has more than one object representation, which object
representation is used shall not affect the value of the result.[59] Where a value is stored in an object
using a type that has more than one object representation for that value, it is unspecified which
representation is used, but a non-value representation shall not be generated.
Footnote 59) It is possible for objects x and y with the same effective type T to have the same value when they are accessed as objects
of type T, but to have different values in other contexts. In particular, if == is defined for type T, then x == y does not imply
that memcmp(&x, &y, sizeof (T))== 0. Furthermore, x == y does not necessarily imply that x and y have the same value;
other operations on values of type T might distinguish between them.
9 Loads and stores of objects with atomic types are done with memory_order_seq_cst semantics.
Forward references: declarations (6.7), expressions (6.5), lvalues, arrays, and function designators
(<IP_ADDRESS>), order and consistency (7.17.3).
<IP_ADDRESS> [Integer types]
1 For unsigned integer types the bits of the object representation shall be divided into two groups:
value bits and padding bits. If there are N value bits, each bit shall represent a different power of
2 between 1 and 2N −1 , so that objects of that type shall be capable of representing values from 0
to 2N − 1 using a pure binary representation; this shall be known as the value representation. The
values of any padding bits are unspecified. The number of value bits N is called the width of the
unsigned integer type. The type bool shall have one value bit and (sizeof(bool)*CHAR_BIT)- 1
padding bits. Otherwise, there need not be any padding bits; unsigned char shall not have any
padding bits.
2 For signed integer types, the bits of the object representation shall be divided into three groups:
value bits, padding bits, and the sign bit. If the corresponding unsigned type has width N , the
signed type uses the same number of N bits, its width, as value bits and sign bit. N − 1 are value
bits and the remaining bit is the sign bit. Each bit that is a value bit shall have the same value as the
same bit in the object representation of the corresponding unsigned type. If the sign bit is zero, it
shall not affect the resulting value. If the sign bit is one, it has value −(2N −1 ). There need not be any
padding bits; signed char shall not have any padding bits.
3 The values of any padding bits are unspecified. A valid object representation of a signed integer
type where the sign bit is zero is a valid object representation of the corresponding unsigned type,
and shall represent the same value. For any integer type, the object representation where all the bits
are zero shall be a representation of the value zero in that type.
4 The precision of an integer type is the number of value bits.
5 NOTE 1 Some combinations of padding bits might generate non-value representations, for example, if one padding bit is a
parity bit. Regardless, no arithmetic operation on valid values can generate a non-value representation other than as part of
an exceptional condition such as an integer overflow, and this cannot occur with unsigned types. All other combinations of
padding bits are alternative object representations of the value specified by the value bits.
6 NOTE 2 The sign representation defined in this document is called two’s complement. Previous revisions of this document
additionally allowed other sign representations.
7 NOTE 3 For unsigned integer types the width and precision are the same, while for signed integer types the width is one
greater than the precision.
6.2.7 [Compatible type and composite type]
1 Two types are compatible types if they are the same. Additional rules for determining whether two
types are compatible are described in 6.7.2 for type specifiers, in 6.7.3 for type qualifiers, and in 6.7.6
for declarators[60] . Moreover, two complete structure, union, or enumerated types declared with the
same tag are compatible if members satisfy the following requirements:
— there shall be a one-to-one correspondence between their members such that each pair of
corresponding members are declared with compatible types;
— if one member of the pair is declared with an alignment specifier, the other is declared with an
equivalent alignment specifier;
— and, if one member of the pair is declared with a name, the other is declared with the same
name.
For two structures, corresponding members shall be declared in the same order. For two structures or
unions, corresponding bit-fields shall have the same widths. For two enumerations, corresponding
members shall have the same values; if one has a fixed underlying type, then the other shall have a
compatible fixed underlying type. For determining type compatibility, anonymous structures and
unions are considered a regular member of the containing structure or union type, and the type
of an anonymous structure or union is considered compatible to the type of another anonymous
structure or union, respectively, if their members fulfill the above requirements.
Furthermore, two structure, union, or enumerated types declared in separate translation units are
compatible in the following cases:
— both are declared without tags and they fulfill the requirements above;
— both have the same tag and are completed somewhere in their respective translation units and
they fulfill the requirements above;
— both have the same tag and at least one of the two types is not completed in its translation unit.
Otherwise, the structure, union, or enumerated types are incompatible[61] .
Footnote 60) Two types need not be identical to be compatible.
Footnote 61) A structure, union, or enumerated type without a tag or an incomplete structure, union or enumerated type is not
compatible with any other structure, union or enum type declared in the same translation unit.
2 All declarations that refer to the same object or function shall have compatible type; otherwise, the
behavior is undefined.
3 A composite type can be constructed from two types that are compatible; it is a type that is compatible
with both of the two types and satisfies the following conditions:
— If both types are array types, the following rules are applied:
• If one type is an array of known constant size, the composite type is an array of that size.
• Otherwise, if one type is a variable length array whose size is specified by an expression
that is not evaluated, the behavior is undefined.
• Otherwise, if one type is a variable length array whose size is specified, the composite
type is a variable length array of that size.
• Otherwise, if one type is a variable length array of unspecified size, the composite type is
a variable length array of unspecified size.
• Otherwise, both types are arrays of unknown size and the composite type is an array of
unknown size.
The element type of the composite type is the composite type of the two element types.
— If both types are function types, the type of each parameter in the composite parameter type
list is the composite type of the corresponding parameters.
— If one of the types has a standard attribute, the composite type also has that attribute.
These rules apply recursively to the types from which the two types are derived.
4 For an identifier with internal or external linkage declared in a scope in which a prior declaration of
that identifier is visible[62] , if the prior declaration specifies internal or external linkage, the type of
the identifier at the later declaration becomes the composite type.
Footnote 62) As specified in 6.2.1, the later declaration might hide the prior declaration.
5 EXAMPLE Given the following two file scope declarations:
int f(int (*)(char *), double (*)[3]);
int f(int (*)(char *), double (*)[]);
The resulting composite type for the function is:
int f(int (*)(char *), double (*)[3]);
Forward references: array declarators (<IP_ADDRESS>).
6.2.8 [Alignment of objects]
1 Complete object types have alignment requirements which place restrictions on the addresses at
which objects of that type may be allocated. An alignment is an implementation-defined integer
value representing the number of bytes between successive addresses at which a given object can be
allocated. An object type imposes an alignment requirement on every object of that type: stricter
alignment can be requested using the alignas keyword.
2 A fundamental alignment is a valid alignment less than or equal to alignof (max_align_t). Funda-
mental alignments shall be supported by the implementation for objects of all storage durations.
The alignment requirements of the following types shall be fundamental alignments:
— all atomic, qualified, or unqualified basic types;
— all atomic, qualified, or unqualified enumerated types;
— all atomic, qualified, or unqualified pointer types;
— all array types whose element type has a fundamental alignment requirement;
— all types specified in Clause 7 as complete object types;
— all structure or union types all of whose elements have types with fundamental alignment
requirements and none of whose elements have an alignment specifier specifying an alignment
that is not a fundamental alignment.
3 An extended alignment is represented by an alignment greater than alignof (max_align_t). It is
implementation-defined whether any extended alignments are supported and the storage durations
for which they are supported. A type having an extended alignment requirement is an over-aligned
type.[63]
Footnote 63) Every over-aligned type is, or contains, a structure or union type with a member to which an extended alignment has
been applied.
4 Alignments are represented as values of the type size_t. Valid alignments include only fundamental
alignments, plus an additional implementation-defined set of values, which may be empty. Every
valid alignment value shall be a nonnegative integral power of two.
5 Alignments have an order from weaker to stronger or stricter alignments. Stricter alignments have
larger alignment values. An address that satisfies an alignment requirement also satisfies any weaker
valid alignment requirement.
6 The alignment requirement of a complete type can be queried using an alignof expression. The
types char, signed char, and unsigned char shall have the weakest alignment requirement.
7 Comparing alignments is meaningful and provides the obvious results:
— Two alignments are equal when their numeric values are equal.
— Two alignments are different when their numeric values are not equal.
— When an alignment is larger than another it represents a stricter alignment.
6.2.9 [Encodings]
1 The literal encoding is an implementation-defined mapping of the characters of the execution character
set to the values in a character constant (<IP_ADDRESS>) or string literal (6.4.5). It shall support a mapping
from all the basic execution character set values into the implementation-defined encoding. It may
contain multibyte character sequences (<IP_ADDRESS>).
2 The wide literal encoding is an implementation-defined mapping of the characters of the execution
character set to the values in a wchar_t character constant (<IP_ADDRESS>) or a wchar_t string literal (6.4.5).
It shall support a mapping from all the basic execution character set values into the implementation-
defined encoding. The mapping shall produce values identical to the literal encoding for all the basic
execution character set values if an implementation does not define __STDC_MB_MIGHT_NEQ_WC__ .
One or more values may map to one or more values of the extended execution character set.
6.3 [Conversions]
1 Several operators convert operand values from one type to another automatically. This subclause
specifies the result required from such an implicit conversion, as well as those that result from a cast
operation (an explicit conversion). The list in <IP_ADDRESS> summarizes the conversions performed by most
ordinary operators; it is supplemented as required by the discussion of each operator in 6.5.
2 Unless explicitly stated otherwise, conversion of an operand value to a compatible type causes no
change to the value or the representation.
Forward references: cast operators (6.5.4).
6.3.1 [Arithmetic operands]
<IP_ADDRESS> [Boolean, characters, and integers]
1 Every integer type has an integer conversion rank defined as follows:
— No two signed integer types shall have the same rank, even if they have the same representa-
tion.
— The rank of a signed integer type shall be greater than the rank of any signed integer type with
less precision.
— The rank of long long int shall be greater than the rank of long int, which shall be greater
than the rank of int, which shall be greater than the rank of short int, which shall be greater
than the rank of signed char.
— The rank of a bit-precise signed integer type shall be greater than the rank of any standard
integer type with less width or any bit-precise integer type with less width.
— The rank of any unsigned integer type shall equal the rank of the corresponding signed integer
type, if any.
— The rank of any standard integer type shall be greater than the rank of any extended integer
type with the same width or bit-precise integer type with the same width.
— The rank of any bit-precise integer type relative to an extended integer type of the same width
is implementation-defined.
— The rank of char shall equal the rank of signed char and unsigned char.
— The rank of bool shall be less than the rank of all other standard integer types.
— The rank of any enumerated type shall equal the rank of the compatible integer type (see
<IP_ADDRESS>).
— The rank of any extended signed integer type relative to another extended signed integer
type with the same precision is implementation-defined, but still subject to the other rules for
determining the integer conversion rank.
— For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has greater rank than
T3 , then T1 has greater rank than T3.
2 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.
The value from a bit-field of a bit-precise integer type is converted to the corresponding bit-precise
type. If the original type is not a bit-precise integer type (6.2.5) and 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[64] ;
otherwise, it is converted to an unsigned int. These are called the integer promotions[65] . All other
types are unchanged by the integer promotions.
Footnote 64) E.g.,
unsigned _BitInt(7): 2 is a bit-field that can hold the values −2, −1, 0, 1, and converts to
unsigned _BitInt(7).
Footnote 65) The integer promotions are applied only: as part of the usual arithmetic conversions, to certain argument expressions, to
the operands of the unary + ,- , and ~ operators, and to both operands of the shift operators, as specified by their respective
subclauses.
3 The integer promotions preserve value including sign. As discussed earlier, whether a "plain" char
can hold negative values is implementation-defined.
Forward references: enumeration specifiers (<IP_ADDRESS>), structure and union specifiers (<IP_ADDRESS>).
<IP_ADDRESS> [Boolean type]
1 When any scalar value is converted to bool, the result is false if the value is a zero (for arithmetic
types), null (for pointer types), or the scalar has type nullptr_t; otherwise, the result is true.
<IP_ADDRESS> [Signed and unsigned integers]
1 When a value with integer type is converted to another integer type other than bool, if the value
can be represented by the new type, it is unchanged.
2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting
one more than the maximum value that can be represented in the new type until the value is in the
range of the new type.[66]
Footnote 66) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.
3 Otherwise, the new type is signed and the value cannot be represented in it; either the result is
implementation-defined or an implementation-defined signal is raised.
<IP_ADDRESS> [Real floating and integer]
1 When a finite value of standard floating type is converted to an integer type other than bool, the
fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part
cannot be represented by the integer type, the behavior is undefined.[67]
Footnote 67) The remaindering operation performed when a value of integer type is converted to unsigned type need not be
performed when a value of real floating type is converted to unsigned type. Thus, the range of portable real floating values is
(−1, Utype_MAX + 1).
2 When a finite value of decimal floating type is converted to an integer type other than bool, the
fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part
cannot be represented by the integer type, the "invalid" floating-point exception shall be raised and
the result of the conversion is unspecified.
3 When a value of integer type is converted to a standard floating type, if the value being converted
can be represented exactly in the new type, it is unchanged. If the value being converted is in the
range of values that can be represented but cannot be represented exactly, the result is either the
nearest higher or nearest lower representable value, chosen in an implementation-defined manner.
If the value being converted is outside the range of values that can be represented, the behavior is
undefined. Results of some implicit conversions may be represented in greater range and precision
than that required by the new type (see <IP_ADDRESS> and <IP_ADDRESS>).
4 When a value of integer type is converted to a decimal floating type, if the value being converted
can be represented exactly in the new type, it is unchanged. If the value being converted cannot
be represented exactly, the result shall be correctly rounded with exceptions raised as specified in
IEC 60559.
<IP_ADDRESS> [Real floating types]
1 When a value of real floating type is converted to a real floating type, if the value being converted
can be represented exactly in the new type, it is unchanged.
2 When a value of real floating type is converted to a standard floating type, if the value being
converted is in the range of values that can be represented but cannot be represented exactly, the
result is either the nearest higher or nearest lower representable value, chosen in an implementation-
defined manner. If the value being converted is outside the range of values that can be represented,
the behavior is undefined.
3 When a value of real floating type is converted to a decimal floating type, if the value being converted
cannot be represented exactly, the result is correctly rounded with exceptions raised as specified in
IEC 60559.
4 Results of some implicit conversions may be represented in greater range and precision than that
required by the new type (see <IP_ADDRESS> and <IP_ADDRESS>).
<IP_ADDRESS> [Complex types]
1 When a value of complex type is converted to another complex type, both the real and imaginary
parts follow the conversion rules for the corresponding real types.
<IP_ADDRESS> [Real and complex]
1 When a value of real type is converted to a complex type, the real part of the complex result value is
determined by the rules of conversion to the corresponding real type and the imaginary part of the
complex result value is a positive zero or an unsigned zero.
2 When a value of complex type is converted to a real type other than bool,[68] the imaginary part of
the complex value is discarded and the value of the real part is converted according to the conversion
rules for the corresponding real type.
Footnote 68) See <IP_ADDRESS>.
<IP_ADDRESS> [Usual arithmetic conversions]
1 Many operators that expect operands of arithmetic type cause conversions and yield result types in
a similar way. The purpose is to determine a common real type for the operands and result. For the
specified operands, each operand is converted, without change of type domain, to a type whose
corresponding real type is the common real type. Unless explicitly stated otherwise, the common
real type is also the corresponding real type of the result, whose type domain is the type domain of
the operands if they are the same, and complex otherwise. This pattern is called the usual arithmetic
conversions:
If one operand has decimal floating type, the other operand shall not have standard floating,
complex, or imaginary type.
First, if the type of either operand is _Decimal128 , the other operand is converted to
_Decimal128 .
Otherwise, if the type of either operand is _Decimal64 , the other operand is converted to
_Decimal64 .
Otherwise, if the type of either operand is _Decimal32 , the other operand is converted to
_Decimal32 .
Otherwise, if the corresponding real type of either operand is long double, the other operand
is converted, without change of type domain, to a type whose corresponding real type is
long double.
Otherwise, if the corresponding real type of either operand is double, the other operand is
converted, without change of type domain, to a type whose corresponding real type is double.
Otherwise, if the corresponding real type of either operand is float, the other operand is
converted, without change of type domain, to a type whose corresponding real type is float.[69]
Otherwise, the integer promotions are performed on both operands. Then the following rules
are applied to the promoted operands:
If both operands have the same type, then no further conversion is needed.
Otherwise, if both operands have signed integer types or both have unsigned integer
types, the operand with the type of lesser integer conversion rank is converted to the type
of the operand with greater rank.
Otherwise, if the operand that has unsigned integer type has rank greater or equal to
the rank of the type of the other operand, then the operand with signed integer type is
converted to the type of the operand with unsigned integer type.
Otherwise, if the type of the operand with signed integer type can represent all of the
values of the type of the operand with unsigned integer type, then the operand with
unsigned integer type is converted to the type of the operand with signed integer type.
Otherwise, both operands are converted to the unsigned integer type corresponding to
the type of the operand with signed integer type.
Footnote 69) For example, addition of a double _Complex and a float entails just the conversion of the float operand to double
(and yields a double _Complex result).
2 The values of floating operands and of the results of floating expressions may be represented in
greater range and precision than that required by the type; the types are not changed thereby.
See <IP_ADDRESS>.2 regarding evaluation formats.
3 EXAMPLE 1 One consequence of _BitInt being exempt from the integer promotion rules (6.3.1) is that a _BitInt operand
of a binary operator is not always promoted to an int or unsigned int as part of the usual arithmetic conversions. Instead,
a lower-ranked operand is converted to the higher-rank operand type and the result of the operation is the higher-ranked
type.
_BitInt(2) a2 = 1;
_BitInt(3) a3 = 2;
_BitInt(33) a33 = 1;
char c = 3;
a2 * a3 /* As part of the multiplication, a2 is converted to
_BitInt(3) and the result type is _BitInt(3). */
a2 * c /* As part of the multiplication, c is promoted to int,
a2 is converted to int and the result type is int. */
a33 * c /* As part of the multiplication, c is promoted to int,
then converted to _BitInt(33) and the result type
is _BitInt(33). */
void func(_BitInt(8) a1, _BitInt(24) a2) {
/* Cast one of the operands to 32-bits to guarantee the
result of the multiplication can contain all possible
values. */
_BitInt(32) a3 = a1 * (_BitInt(32))a2;
}
6.3.2 [Other operands]
<IP_ADDRESS> [Lvalues, arrays, and function designators]
1 An lvalue is an expression (with an object type other than void) that potentially designates an
object;[70] if an lvalue does not designate an object when it is evaluated, the behavior is undefined.
When an object is said to have a particular type, the type is specified by the lvalue used to designate
the object. A modifiable lvalue is an lvalue that does not have array type, does not have an incomplete
type, does not have a const-qualified type, and if it is a structure or union, does not have any
member (including, recursively, any member or element of all contained aggregates or unions) with
a const-qualified type.
Footnote 70) The name "lvalue" comes originally from the assignment expression E1 = E2, in which the left operand E1 is required to
be a (modifiable) lvalue. It is perhaps better considered as representing an object "locator value". What is sometimes called
"rvalue" is in this document described as the "value of an expression".
An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary expression that is a
pointer to an object, *E is an lvalue that designates the object to which E points.
2 Except when it is the operand of the sizeof operator, or the typeof operators, the unary & operator,
the ++ operator, the-- operator, or the left operand of the . operator or an assignment operator, an
lvalue that does not have array type is converted to the value stored in the designated object (and is
no longer an lvalue); this is called lvalue conversion. If the lvalue has qualified type, the value has the
unqualified version of the type of the lvalue; additionally, if the lvalue has atomic type, the value has
the non-atomic version of the type of the lvalue; otherwise, the value has the type of the lvalue. If the
lvalue has an incomplete type and does not have array type, the behavior is undefined. If the lvalue
designates an object of automatic storage duration that could have been declared with the register
storage class (never had its address taken), and that object is uninitialized (not declared with an
initializer and no assignment to it has been performed prior to use), the behavior is undefined.
3 Except when it is the operand of the sizeof operator, or typeof operators, or the unary & operator,
or is a string literal used to initialize an array, an expression that has type "array of type" is converted
to an expression with type "pointer to type" that points to the initial element of the array object and
is not an lvalue. If the array object has register storage class, the behavior is undefined.
4 A function designator is an expression that has function type. Except when it is the operand of the
sizeof operator[71] , a typeof operator, or the unary & operator, a function designator with type
"function returning type" is converted to an expression that has type "pointer to function returning
type".
Forward references: address and indirection operators (<IP_ADDRESS>), assignment operators (6.5.16),
common definitions <stddef.h> (7.21), initialization (6.7.10), postfix increment and decrement
operators (<IP_ADDRESS>), prefix increment and decrement operators (<IP_ADDRESS>), the sizeof and alignof
operators (<IP_ADDRESS>), structure and union members (<IP_ADDRESS>).
Footnote 71) Because this conversion does not occur, the operand of the sizeof operator remains a function designator and violates
the constraints in <IP_ADDRESS>.
<IP_ADDRESS> [void]
1 The (nonexistent) value of a void expression (an expression that has type void) shall not be used in any
way, and implicit or explicit conversions (except to void) shall not be applied to such an expression.
If an expression of any other type is evaluated as a void expression, its value or designator is
discarded. (A void expression is evaluated for its side effects.)
<IP_ADDRESS> [Pointers]
1 A pointer to void may be converted to or from a pointer to any object type. A pointer to any object
type may be converted to a pointer to void and back again; the result shall compare equal to the
original pointer.
2 For any qualifier q, a pointer to a non-q-qualified type may be converted to a pointer to the q-qualified
version of the type; the values stored in the original and converted pointers shall compare equal.
3 An integer constant expression with the value 0, such an expression cast to type void *, or the
predefined constant nullptr is called a null pointer constant[72] . If a null pointer constant or a value
of the type nullptr_t (which is necessarily the value nullptr) is converted to a pointer type, the
resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or
function.
Footnote 72) The macro NULL is defined in <stddef.h> (and other headers) as a null pointer constant; see 7.21.
4 Conversion of a null pointer to another pointer type yields a null pointer of that type. Any two null
pointers shall compare equal.
5 An integer may be converted to any pointer type. Except as previously specified, the result is
implementation-defined, might not be correctly aligned, might not point to an entity of the referenced
type, and might produce an indeterminate representation when stored into an object[73] .
Footnote 73) The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to be consistent with
the addressing structure of the execution environment.
6 Any pointer type may be converted to an integer type. Except as previously specified, the result
is implementation-defined. If the result cannot be represented in the integer type, the behavior is
undefined. The result need not be in the range of values of any integer type.
7 A pointer to an object type may be converted to a pointer to a different object type. If the resulting
pointer is not correctly aligned[74] for the referenced type, the behavior is undefined. Otherwise,
when converted back again, the result shall compare equal to the original pointer. When a pointer to
an object is converted to a pointer to a character type, the result points to the lowest addressed byte
of the object. Successive increments of the result, up to the size of the object, yield pointers to the
remaining bytes of the object.
Footnote 74) In general, the concept "correctly aligned" is transitive: if a pointer to type A is correctly aligned for a pointer to type B,
which in turn is correctly aligned for a pointer to type C, then a pointer to type A is correctly aligned for a pointer to type C.
8 A pointer to a function of one type may be converted to a pointer to a function of another type and
back again; the result shall compare equal to the original pointer. If a converted pointer is used to
call a function whose type is not compatible with the referenced type, the behavior is undefined.
<IP_ADDRESS> [nullptr_t]
1 The type nullptr_t may be converted to bool or to a pointer type. The result is false or the null
pointer value, respectively.
2 The type nullptr_t may be converted to itself.
Forward references: cast operators (6.5.4), equality operators (6.5.9), integer types capable of
holding object pointers (<IP_ADDRESS>), simple assignment (<IP_ADDRESS>).
6.4 [Lexical elements]
1 Syntax
token:
keyword
identifier
constant
string-literal
punctuator
preprocessing-token:
header-name
identifier
pp-number
character-constant
string-literal
punctuator
each universal-character-name that cannot be one of the above
each non-white-space character that cannot be one of the above
Constraints
2 Each preprocessing token that is converted to a token shall have the lexical form of a keyword, an
identifier, a constant, a string literal, or a punctuator. A single universal character name shall match
one of the other preprocessing token categories.
Semantics
3 A token is the minimal lexical element of the language in translation phases 7 and 8. The categories of
tokens are: keywords, identifiers, constants, string literals, and punctuators. A preprocessing token
is the minimal lexical element of the language in translation phases 3 through 6. The categories of
preprocessing tokens are: header names, identifiers, preprocessing numbers, character constants,
string literals, punctuators, and both single universal character names as well as single non-white-
space characters that do not lexically match the other preprocessing token categories.[75] If a ’ or a "
character matches the last category, the behavior is undefined. Preprocessing tokens can be separated
by white space; this consists of comments (described later), or white-space characters (space, horizontal
tab, new-line, vertical tab, and form-feed), or both. As described in 6.10, in certain circumstances
during translation phase 4, white space (or the absence thereof) serves as more than preprocessing
token separation. White space may appear within a preprocessing token only as part of a header
name or between the quotation characters in a character constant or string literal.
Footnote 75) An additional category, placemarkers, is used internally in translation phase 4 (see <IP_ADDRESS>); it cannot occur in source
files.
4 If the input stream has been parsed into preprocessing tokens up to a given character, the next
preprocessing token is the longest sequence of characters that could constitute a preprocessing token.
There is one exception to this rule: header name preprocessing tokens are recognized only within
#include and #embed preprocessing directives, in __has_include and __has_embed expressions,
as well as in implementation-defined locations within #pragma directives. In such contexts, a
sequence of characters that could be either a header name or a string literal is recognized as the
former.
5 EXAMPLE 1 The program fragment 1Ex is parsed as a preprocessing number token (one that is not a valid floating or integer
constant token), even though a parse as the pair of preprocessing tokens 1 and Ex might produce a valid expression (for
example, if Ex were a macro defined as +1 ). Similarly, the program fragment 1E1 is parsed as a preprocessing number (one
that is a valid floating constant token), whether or not E is a macro name.
6 EXAMPLE 2 The program fragment x+++++y is parsed as x ++ ++ + y, which violates a constraint on increment operators,
even though the parse x ++ + ++ y might yield a correct expression.
Forward references: character constants (<IP_ADDRESS>), comments (6.4.9), expressions (6.5), floating
constants (<IP_ADDRESS>), header names (6.4.7), macro replacement (6.10.4), postfix increment and decrement
operators (<IP_ADDRESS>), prefix increment and decrement operators (<IP_ADDRESS>), preprocessing directives (6.10),
preprocessing numbers (6.4.8), string literals (6.4.5).
6.4.1 [Keywords]
1 Syntax
keyword: one of
alignas enum short void
alignof extern signed volatile
auto false sizeof while
bool float static _Atomic
break for static_assert _BitInt
case goto struct _Complex
char if switch _Decimal128
const inline thread_local _Decimal32
constexpr int true _Decimal64
continue long typedef _Generic
default nullptr typeof _Imaginary
do register typeof_unqual _Noreturn
double restrict union
else return unsigned
Semantics
2 The above tokens (case sensitive) are reserved (in translation phases 7 and 8) for use as keywords
except in an attribute token, and shall not be used otherwise. The keyword _Imaginary is reserved
for specifying imaginary types.[76]
Footnote 76) One possible specification for imaginary types appears in Annex G.
3 The following table provides alternate spellings for certain keywords. These can be used wherever
the keyword can[77] .
Keyword Alternative Spelling
alignas _Alignas
alignof _Alignof
bool _Bool
static_assert _Static_assert
thread_local _Thread_local
The spelling of these keywords, their alternate forms, and of false and true inside expressions that
are subject to the # and ## preprocessing operators is unspecified[78] .
Footnote 77) These alternative keywords are obsolescent features and should not be used for new code and development.
Footnote 78) The intent of this specification is to allow but not force the implementation of the corresponding feature by means of a
predefined macro.
6.4.2 [Identifiers]
<IP_ADDRESS> [General]
1 Syntax
identifier:
identifier-start
identifier identifier-continue
identifier-start:
nondigit
XID_Start character
universal-character-name of class XID_Start
identifier-continue:
digit
nondigit
XID_Continue character
universal-character-name of class XID_Continue
nondigit: one of
_ a b c d e f g h i j k l m
n o p q r s t u v w x y z
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
digit: one of
0 1 2 3 4 5 6 7 8 9
Semantics
2 An XID_Start character is an implementation-defined character whose corresponding code point
in ISO/IEC 10646 has the XID_Start property. An XID_Continue character is an implementation-
defined character whose corresponding code point in ISO/IEC 10646 has the XID_Continue property.
An identifier is a sequence of one identifier start character followed by 0 or more identifier continue
characters, which designates one or more entities as described in 6.2.1. Lowercase and uppercase
letters are distinct. There is no specific limit on the maximum length of an identifier.
3 The character classes XID_Start and XID_Continue are Derived Core Properties as described by
UAX #4479) . Each character and universal character name in an identifier shall designate a character
whose encoding in ISO/IEC 10646 has the XID_Continue property. The initial character (which
may be a universal character name) shall designate a character whose encoding in ISO/IEC 10646
has the XID_Start property. An identifier shall conform to Normalization Form C as specified in
ISO/IEC 10646. Annex D provides an overview of the conforming identifiers.
4 NOTE 1 Uppercase and lowercase letters are considered different for all identifiers.
5 NOTE 2 In translation phase 4 (4), the term identifier also includes those preprocessing tokens (6.4.8) differentiated as
keywords (6.4.1) in the later translation phase 7 (7).
6 When preprocessing tokens are converted to tokens during translation phase 7, if a preprocessing
token could be converted to either a keyword or an identifier, it is converted to a keyword except in
an attribute token.
7 Some identifiers are reserved.
— All identifiers that begin with a double underscore (__ ) or begin with an underscore (_ )
followed by an uppercase letter are reserved for any use, except those identifiers which are
lexically identical to keywords[80] .
— All identifiers that begin with an underscore are reserved for use as identifiers with file scope
in both the ordinary and tag name spaces.
Other identifiers may be reserved, see 7.1.3.
Footnote 80) This allows a reserved identifier that matches the spelling of a keyword to be used as a macro name by the program.
8 If the program declares or defines an identifier in a context in which it is reserved (other than as
allowed by 7.1.4), the behavior is undefined.
9 If the program defines a reserved identifier or attribute token described in <IP_ADDRESS> as a macro name,
or removes (with #undef) any macro definition of an identifier in the first group listed above or
attribute token described in <IP_ADDRESS>, the behavior is undefined.
10 Some identifiers may be potentially reserved. A potentially reserved identifier is an identifier which is
not reserved unless made so by an implementation providing the identifier (7.1.3) but is anticipated
to become reserved by an implementation or a future version of this document.
Recommended Practice
11 Implementations are encouraged to issue a diagnostic message when a potentially reserved identifier
is declared or defined for any use that is not implementation-compatible (see below) in a context
where the potentially reserved identifier may be reserved under a conforming implementation. This
brings attention to a potential conflict when porting a program to a future revision of this document.
12 An implementation-compatible use of a potentially reserved identifier is a declaration of an external
name where the name is provided by the implementation as an external name and where the
declaration declares an object or function with a type that is compatible with the type of the object
or function provided by the implementation under that name.
Implementation limits
13 As discussed in <IP_ADDRESS>, an implementation may limit the number of significant initial characters
in an identifier; the limit for an external name (an identifier that has external linkage) may be more
restrictive than that for an internal name (a macro name or an identifier that does not have external
linkage). The number of significant characters in an identifier is implementation-defined.
14 Any identifiers that differ in a significant character are different identifiers. If two identifiers differ
only in nonsignificant characters, the behavior is undefined.
Forward references: universal character names (6.4.3), macro replacement (6.10.4), reserved library
identifiers (7.1.3), use of library functions (7.1.4), attributes (<IP_ADDRESS>).
<IP_ADDRESS> [Predefined identifiers]
1 Semantics
The identifier __func__ shall be implicitly declared by the translator as if, immediately following
the opening brace of each function definition, the declaration
static const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.[81]
Footnote 81) Since the name __func__ is reserved for any use by the implementation (7.1.3), if any other identifier is explicitly declared
using the name __func__ , the behavior is undefined.
2 This name is encoded as if the implicit declaration had been written in the source character set and
then translated into the execution character set as indicated in translation phase 5.
3 EXAMPLE Consider the code fragment:
#include <stdio.h>
void myfunc(void)
{
printf("%s\n", __func__);
/* ... */
}
Each time the function is called, it will print to the standard output stream:
myfunc
Forward references: function definitions (6.9.1).
6.4.3 [Universal character names]
1 Syntax
universal-character-name:
\u hex-quad
\U hex-quad hex-quad
hex-quad:
hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit
Constraints
2 A universal character name shall not designate a code point where the hexadecimal value is:
— less than 00A0 other than 0024 ($), 0040 (@), or 0060 (` );
— in the range D800 through DFFF inclusive; or
— greater than 10FFFF[82] .
Description
Footnote 82) The disallowed characters are the characters in the basic character set and the code positions reserved by ISO/IEC 10646
for control characters, the character DELETE, the S-zone (reserved for use by UTF-16), and characters too large to be encoded
by ISO/IEC 10646. Disallowed universal character escape sequences can still be specified with hexadecimal and octal escape
sequences (<IP_ADDRESS>).
3 Universal character names may be used in identifiers, character constants, and string literals to
designate characters that are not in the basic character set.
Semantics
4 The universal character name \U nnnnnnnn designates the character whose eight-digit short identifier
(as specified by ISO/IEC 10646) is nnnnnnnn.[83] Similarly, the universal character name \u nnnn
designates the character whose four-digit short identifier is nnnn (and whose eight-digit short
identifier is 0000nnnn).
Footnote 83) Short identifiers for characters were first specified in ISO/IEC 10646–1:1993/Amd 9:1997.
6.4.4 [Constants]
1 Syntax
constant:
integer-constant
floating-constant
enumeration-constant
character-constant
predefined-constant
Constraints
2 Each constant shall have a type and the value of a constant shall be in the range of representable
values for its type.
Semantics
3 Each constant has a type, determined by its form and value, as detailed later.
<IP_ADDRESS> [Integer constants]
1 Syntax
integer-constant:
decimal-constant integer-suffixopt
octal-constant integer-suffixopt
hexadecimal-constant integer-suffixopt
binary-constant integer-suffixopt
decimal-constant:
nonzero-digit
decimal-constant ’opt digit
octal-constant:
0
octal-constant ’opt octal-digit
hexadecimal-constant:
hexadecimal-prefix hexadecimal-digit-sequence
binary-constant:
binary-prefix binary-digit
binary-constant ’opt binary-digit
hexadecimal-prefix: one of
0x 0X
binary-prefix: one of
0b 0B
nonzero-digit: one of
1 2 3 4 5 6 7 8 9
octal-digit: one of
0 1 2 3 4 5 6 7
hexadecimal-digit-sequence:
hexadecimal-digit
hexadecimal-digit-sequence ’opt hexadecimal-digit
hexadecimal-digit: one of
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F
binary-digit: one of
0 1
integer-suffix:
unsigned-suffix long-suffixopt
unsigned-suffix long-long-suffix
unsigned-suffix bit-precise-int-suffix
long-suffix unsigned-suffixopt
long-long-suffix unsigned-suffixopt
bit-precise-int-suffix unsigned-suffixopt
bit-precise-int-suffix: one of
wb WB
unsigned-suffix: one of
u U
long-suffix: one of
l L
long-long-suffix: one of
ll LL
Description
2 An integer constant begins with a digit, but has no period or exponent part. It may have a prefix that
specifies its base and a suffix that specifies its type. An optional separating single quote character (
’ ) in an integer or floating constant is called a digit separator. Digit separators are ignored when
determining the value of the constant.
3 EXAMPLE
0b11’10’11’01 /* 0b11101101 */
’1’2 /* character constant ’1’ followed by integer constant 2,
not the integer constant 12 */
11’22 /* 1122 */
0x’FFFF’FFFF /* invalid hexadecimal constant (’ cannot appear after 0x) */
0x1’2’3’4AB’C’D /* 0x1234ABCD */
4 A decimal constant begins with a nonzero digit and consists of a sequence of decimal digits. An
octal constant consists of the prefix 0 optionally followed by a sequence of the digits 0 through 7
only. A hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of the decimal
digits and the letters a (or A) through f (or F) with values 10 through 15 respectively. A binary
constant consists of the prefix 0b or 0B followed by a sequence of the digits 0 or 1.
Semantics
5 The value of a decimal constant is computed base 10; that of an octal constant, base 8; that of a
hexadecimal constant, base 16; that of a binary constant, base 2. The lexically first digit is the most
significant.
6 The type of an integer constant is the first of the corresponding list in which its value can be
represented.
Octal, Hexadecimal or Binary
Suffix Decimal Constant Constant
none int int
long int unsigned int
long long int long int
unsigned long int
long long int
unsigned long long int
u or U unsigned int unsigned int
unsigned long int unsigned long int
unsigned long long int unsigned long long int
l or L long int long int
long long int unsigned long int
long long int
unsigned long long int
Both u or U unsigned long int unsigned long int
and l or L unsigned long long int unsigned long long int
ll or LL long long int long long int
unsigned long long int
Both u or U unsigned long long int unsigned long long int
and ll or LL
wb or WB _BitInt(N) where the width N _BitInt(N) where the width N
is the smallest N greater than is the smallest N greater than
1 which can accommodate 1 which can accommodate
the value and the sign bit. the value and the sign bit.
Both u or U unsigned _BitInt(N) where the unsigned _BitInt(N) where the
and wb or WB width N is the smallest N width N is the smallest N
greater than 0 which can greater than 0 which can
accommodate the value. accommodate the value.
7 If an integer constant cannot be represented by any type in its list, it may have an extended integer
type, if the extended integer type can represent its value. If all of the types in the list for the constant
are signed, the extended integer type shall be signed. If all of the types in the list for the constant
are unsigned, the extended integer type shall be unsigned. If the list contains both signed and
unsigned types, the extended integer type may be signed or unsigned. If an integer constant cannot
be represented by any type in its list and has no extended integer type, then the integer constant has
no type.
8 EXAMPLE 1 The wb suffix results in an _BitInt that includes space for the sign bit even if the value of the constant is
positive or was specified in hexadecimal or octal notation.
-3wb /* Yields an _BitInt(3) that is then negated; two value
bits, one sign bit */
-0x3wb /* Yields an _BitInt(3) that is then negated; two value
bits, one sign bit */
3wb /* Yields an _BitInt(3); two value bits, one sign bit */
3uwb /* Yields an unsigned _BitInt(2) */
-3uwb /* Yields an unsigned _BitInt(2) that is then negated,
resulting in wrap-around */
Forward references: preprocessing numbers (6.4.8), numeric conversion functions (7.24.1).
<IP_ADDRESS> [Floating constants]
1 Syntax
floating-constant:
decimal-floating-constant
hexadecimal-floating-constant
decimal-floating-constant:
fractional-constant exponent-partopt floating-suffixopt
digit-sequence exponent-part floating-suffixopt
hexadecimal-floating-constant:
hexadecimal-prefix hexadecimal-fractional-constant
binary-exponent-part floating-suffixopt
hexadecimal-prefix hexadecimal-digit-sequence
binary-exponent-part floating-suffixopt
fractional-constant:
digit-sequenceopt . digit-sequence
digit-sequence .
exponent-part:
e signopt digit-sequence
E signopt digit-sequence
sign: one of
+ -
digit-sequence:
digit
digit-sequence ’opt digit
hexadecimal-fractional-constant:
hexadecimal-digit-sequenceopt . hexadecimal-digit-sequence
hexadecimal-digit-sequence .
binary-exponent-part:
p signopt digit-sequence
P signopt digit-sequence
floating-suffix: one of
f l F L df dd dl DF DD DL
Constraints
2 A floating suffix df, dd, dl, DF, DD, or DL shall not be used in a hexadecimal floating constant.
Description
3 A floating constant has a significand part that may be followed by an exponent part and a suffix that
specifies its type. The components of the significand part may include a digit sequence representing
the whole-number part, followed by a period ( .), followed by a digit sequence representing the
fraction part. Digit separators (<IP_ADDRESS>) are ignored when determining the value of the constant. The
components of the exponent part are an e, E, p, or P followed by an exponent consisting of an
optionally signed digit sequence. Either the whole-number part or the fraction part has to be present;
for decimal floating constants, either the period or the exponent part has to be present.
Semantics
4 The significand part is interpreted as a (decimal or hexadecimal) rational number; the digit sequence
in the exponent part is interpreted as a decimal integer. For decimal floating constants, the exponent
indicates the power of 10 by which the significand part is to be scaled. For hexadecimal floating
constants, the exponent indicates the power of 2 by which the significand part is to be scaled. For
decimal floating constants, and also for hexadecimal floating constants when FLT_RADIX is not a
power of 2, the result is either the nearest representable value, or the larger or smaller representable
value immediately adjacent to the nearest representable value, chosen in an implementation-defined
manner. For hexadecimal floating constants when FLT_RADIX is a power of 2, the result is correctly
rounded.
5 An unsuffixed floating constant has type double. If suffixed by a floating suffix it has a type
according to the following table:
Suffixes for floating constants
Suffix Type
f, F float
l, L long double
df, DF _Decimal32
dd, DD _Decimal64
dl, DL _Decimal128
6 The values of floating constants may be represented in greater range and precision than that required
by the type (determined by the suffix); the types are not changed thereby. See <IP_ADDRESS>.2 regarding
evaluation formats. [84]
Footnote 84) Hexadecimal floating constants can be used to obtain exact values in the semantic type that are independent of the
evaluation format. Casts produce values in the semantic type, though depend on the rounding mode and may raise the
inexact floating-point exception.
7 Floating constants of decimal floating type that have the same numerical value but different quantum
exponents have distinguishable internal representations. The value shall be correctly rounded as
specified in IEC 60559. The coefficient c and the quantum exponent q of a finite converted decimal
floating-point number (see <IP_ADDRESS>.3) are determined as follows:
— q is set to the value of signopt digit-sequence in the exponent part, if any, or to 0, otherwise.
— If there is a fractional constant, q is decreased by the number of digits to the right of the period
and the period is removed to form a digit sequence.
— c is set to the value of the digit sequence (after any period has been removed).
— Rounding required because of insufficient precision or range in the type of the result will
round c to the full precision available in the type, and will adjust q accordingly within the
limits of the type, provided the rounding does not yield an infinity (in which case the result
is an appropriately signed internal representation of infinity). If the full precision of the type
would require q to be smaller than the minimum for the type, then q is pinned at the minimum
and c is adjusted through the subnormal range accordingly, perhaps to zero.
8 Floating constants are converted to internal format as if at translation-time. The conversion of a
floating constant shall not raise an exceptional condition or a floating-point exception at execution
time. All floating constants of the same source form [85] shall convert to the same internal format
with the same value.
Footnote 85) 1.23 , 1.230 , 123e-2 , 123e-02 , and 1.23L are all different source forms and thus need not convert to the same internal
format and value.
9 EXAMPLE Following are floating constants of type _Decimal64 and their values as triples (s, c, q). Note that for
_Decimal64 , the precision (maximum coefficient length) is 16 and the quantum exponent range is −398 ≤ q ≤ 369.
0.dd (+1, 0, 0)
0.00dd (+1, 0, −2)
123.dd (+1, 123, 0)
1.23E3dd (+1, 123, 1)
1.23E+3dd (+1, 123, 1)
12.3E+7dd (+1, 123, 6)
12.0dd (+1, 120, −1)
12.3dd (+1, 123, −1)
0.00123dd (+1, 123, −5)
1.23E-12dd (+1, 123, −14)
1234.5E-4dd (+1, 12345, −5)
0E+7dd (+1, 0, 7)
12345678901234567890.dd (+1,<PHONE_NUMBER>123457, 4) assuming default rounding and DEC_EVAL_METHOD is 0
or [186]
1234E-400dd (+1, 12, −398) assuming default rounding and DEC_EVAL_METHOD is 0 or 1
1234E-402dd (+1, 0, −398) assuming default rounding and DEC_EVAL_METHOD is 0 or 1
1000.dd (+1, 1000, 0)
.0001dd (+1, 1, −4)
1000.e0dd (+1, 1000, 0)
.0001e0dd (+1, 1, −4)
1000.0dd (+1, 10000, −1)
0.0001dd (+1, 1, −4)
1000.00dd (+1, 100000, −2)
00.0001dd (+1, 1, −4)
001000.dd (+1, 1000, 0)
001000.0dd (+1, 10000, −1)
001000.00dd (+1, 100000, −2)
00.00dd (+1, 0, −2)
00.dd (+1, 0, 0)
.00dd (+1, 0, −2)
00.00e-5dd (+1, 0, −7)
00.e-5dd (+1, 0, −5)
.00e-5dd (+1, 0, −7)
Recommended practice
Footnote 186) Thus, the attributes [[nodiscard]] and [[__nodiscard__]] can be freely interchanged. Implementations are encour-
aged to behave similarly for attribute tokens (including attribute prefixed tokens) they provide.
10 The implementation should produce a diagnostic message if a hexadecimal constant cannot be
represented exactly in its evaluation format; the implementation should then proceed with the
translation of the program.
11 The translation-time conversion of floating constants should match the execution-time conversion
of character strings by library functions, such as strtod, given matching inputs suitable for both
conversions, the same result format, and default execution-time rounding. [87]
Footnote 87) The specification for the library functions recommends more accurate conversion than required for floating constants
(see <IP_ADDRESS>).
12 NOTE Floating constants do not include a sign and are negated by the unary - operator (<IP_ADDRESS>) which negates the rounded
value of the constant. In contrast, the numeric conversion functions in the strto family (<IP_ADDRESS>, <IP_ADDRESS>) include the sign as
part of the input value and convert and round the negated input. Negating before rounding and negating after rounding
might yield different results, depending on the rounding direction and whether the results are correctly rounded. For
example, the results are the same when both are correctly rounded using rounding to nearest or rounding toward zero, but
the results are different when they are inexact and correctly rounded using rounding toward positive infinity or rounding
toward negative infinity.
Conversions yielding exact results require no rounding, so are not affected by the order of negating and rounding. For
types with radix 10, decimal floating constants expressed within the precision and range of the evaluation format convert
exactly. For types whose radix is a power of 2, hexadecimal floating constants expressed within the precision and range of the
evaluation format convert exactly.
Forward references: preprocessing numbers (6.4.8), numeric conversion functions (7.24.1), the
strto function family (<IP_ADDRESS>, <IP_ADDRESS>).
<IP_ADDRESS> [Enumeration constants]
1 Syntax
enumeration-constant:
identifier
Semantics
2 An identifier declared as an enumeration constant for an enumeration without a fixed underlying
type has either type int or the enumerated type, as defined in <IP_ADDRESS>. An identifier declared
as an enumeration constant for an enumeration with a fixed underlying type has the associated
enumeration type.
3 An enumeration constant may be used in an expression (or constant expression) wherever a value
of an integer type may be used.
Forward references: enumeration specifiers (<IP_ADDRESS>).
<IP_ADDRESS> [Character constants]
1 Syntax
character-constant:
encoding-prefixopt ’ c-char-sequence ’
encoding-prefix:
u8
u
U
L
c-char-sequence:
c-char
c-char-sequence c-char
c-char:
any member of the source character set except
the single-quote ’, backslash \ , or new-line character
escape-sequence
escape-sequence:
simple-escape-sequence
octal-escape-sequence
hexadecimal-escape-sequence
universal-character-name
simple-escape-sequence: one of
\’ \" \? \\
\a \b \f \n \r \t \v
octal-escape-sequence:
\ octal-digit
\ octal-digit octal-digit
\ octal-digit octal-digit octal-digit
hexadecimal-escape-sequence:
\x hexadecimal-digit
hexadecimal-escape-sequence hexadecimal-digit
Description
2 An integer character constant is a sequence of one or more multibyte characters enclosed in single-
quotes, as in ’x’ . A UTF-8 character constant is the same, except prefixed by u8. A wchar_t character
constant is prefixed by the letter L. A UTF-16 character constant is prefixed by the letter u. A UTF-32
character constant is prefixed by the letter U. Collectively, wchar_t, UTF-16, and UTF-32 character
constants are called wide character constants. With a few exceptions detailed later, the elements of
the sequence are any members of the source character set; they are mapped in an implementation-
defined manner to members of the execution character set.
3 The single-quote ’, the double-quote ", the question-mark ?, the backslash \, and arbitrary integer
values are representable according to the following table of escape sequences:
single quote ’ \’
double quote " \"
question mark ? \?
backslash \ \\
octal character \ octal digits
hexadecimal character \x hexadecimal digits
4 The double-quote " and question-mark ? are representable either by themselves or by the escape
sequences \" and \?, respectively, but the single-quote ’ and the backslash \ shall be represented,
respectively, by the escape sequences \’ and \\ .
5 The octal digits that follow the backslash in an octal escape sequence are taken to be part of the
construction of a single character for an integer character constant or of a single wide character for a
wide character constant. The numerical value of the octal integer so formed specifies the value of
the desired character or wide character.
6 The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape sequence
are taken to be part of the construction of a single character for an integer character constant or of a
single wide character for a wide character constant. The numerical value of the hexadecimal integer
so formed specifies the value of the desired character or wide character.
7 Each octal or hexadecimal escape sequence is the longest sequence of characters that can constitute
the escape sequence.
8 In addition, characters not in the basic character set are representable by universal character names
and certain non-graphic characters are representable by escape sequences consisting of the back-
slash \ followed by a lowercase letter: \a, \b, \f, \n, \r, \t, and \v.[88]
Constraints
Footnote 88) The semantics of these characters were discussed in 5.2.2. If any other character follows a backslash, the result is not a
token and a diagnostic is required. See "future language directions" (6.11.4).
9 The value of an octal or hexadecimal escape sequence shall be in the range of representable values
for the corresponding type:
Prefix Corresponding Type
none unsigned char
u8 char8_t
L the unsigned type corresponding to wchar_t
u char16_t
U char32_t
10 A UTF-8, UTF-16, or UTF-32 character constant shall not contain more than one character.[89] The
value shall be representable with a single UTF-8, UTF-16, or UTF-32 code unit.
Semantics
Footnote 89) For example u8’ab’ violates this constraint.
11 An integer character constant has type int. The value of an integer character constant containing
a single character that maps to a single value in the literal encoding (6.2.9) is the numerical value
of the representation of the mapped character in the literal encoding interpreted as an integer.
The value of an integer character constant containing more than one character (e.g., ’ab’ ), or
containing a character or escape sequence that does not map to a single value in the literal encoding,
is implementation-defined. If an integer character constant contains a single character or escape
sequence, its value is the one that results when an object with type char whose value is that of the
single character or escape sequence is converted to type int.
12 A UTF-8 character constant has type char8_t. If the UTF8 character constant is not produced
through a hexadecimal or octal escape sequence, the value of a UTF-8 character constant is equal to
its ISO/IEC 10646 code point value, provided that the code point value can be encoded as a single
UTF-8 code unit. Otherwise, the value of the UTF8 character constant is the numeric value specified
in the hexadecimal or octal escape sequence.
13 A UTF-16 character constant has type char16_t which is an unsigned integer types defined in the
<uchar.h> header. If the UTF-16 character constant is not produced through a hexadecimal or octal
escape sequence, the value of a UTF-16 character constant is equal to its ISO/IEC 10646 code point
value, provided that the code point value can be encoded as a single UTF-16 code unit. Otherwise,
the value of the UTF-16 character constant is the numeric value specified in the hexadecimal or octal
escape sequence.
14 A UTF-32 character constant has type char32_t which is an unsigned integer types defined in the
<uchar.h> header. If the UTF-32 character constant is not produced through a hexadecimal or octal
escape sequence, the value of a UTF-32 character constant is equal to its ISO/IEC 10646 code point
value, provided that the code point value can be encoded as a single UTF-32 code unit. Otherwise,
the value of the UTF-32 character constant is the numeric value specified in the hexadecimal or octal
escape sequence.
15 A wchar_t character constant prefixed by the letter L has type wchar_t, an integer type defined in
the <stddef.h> header. The value of a wchar_t character constant containing a single multibyte
character that maps to a single member of the extended execution character set is the wide character
corresponding to that multibyte character in the implementation-defined wide literal encoding
(6.2.9). The value of a wchar_t character constant containing more than one multibyte character or a
single multibyte character that maps to multiple members of the extended execution character set,
or containing a multibyte character or escape sequence not represented in the extended execution
character set, is implementation-defined.
16 EXAMPLE 1 The construction ’\0’ is commonly used to represent the null character.
17 EXAMPLE 2 Consider implementations that use eight bits for objects that have type char. In an implementation in which
type char has the same range of values as signed char, the integer character constant ’\xFF’ has the value −1; if type
char has the same range of values as unsigned char, the character constant ’\xFF’ has the value +255.
18 EXAMPLE 3 Even if eight bits are used for objects that have type char, the construction ’\x123’ specifies an integer character
constant containing only one character, since a hexadecimal escape sequence is terminated only by a non-hexadecimal
character. To specify an integer character constant containing the two characters whose values are ’\x12’ and ’3’ , the
construction ’\0223’ can be used, since an octal escape sequence is terminated after three octal digits. (The value of this
two-character integer character constant is implementation-defined.)
19 EXAMPLE 4 Even if 12 or more bits are used for objects that have type wchar_t, the construction L’\1234’ specifies the
implementation-defined value that results from the combination of the values 0123 and ’4’ .
Forward references: common definitions <stddef.h> (7.21), the mbtowc function (<IP_ADDRESS>), Uni-
code utilities <uchar.h> (7.30).
<IP_ADDRESS> [Predefined constants]
1 Syntax
predefined-constant:
false
true
nullptr
Description
2 Some keywords represent constants of a specific value and type.
3 The keywords false and true are constants of type bool with a value of 0 for false and 1 for
true[90] .
Footnote 90) The constants false and true promote to type int, see <IP_ADDRESS>. When used for arithmetic, in translation phase 4, they are
signed values and the result of such arithmetic is consistent with the results of later translation phases.
4 The keyword nullptr represents a null pointer constant. Details of its type are described in 7.21.2.
6.4.5 [String literals]
1 Syntax
string-literal:
encoding-prefixopt " s-char-sequenceopt "
s-char-sequence:
s-char
s-char-sequence s-char
s-char:
any member of the source character set except
the double-quote ", backslash \, or new-line character
escape-sequence
Constraints
2 If a sequence of adjacent string literal tokens includes prefixed string literal tokens, the prefixed
tokens shall all have the same prefix.
Description
3 A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes,
as in "xyz". A UTF-8 string literal is the same, except prefixed by u8. A wchar_t string literal is the
same, except prefixed by L. A UTF-16 string literal is the same, except prefixed by u. A UTF-32 string
literal is the same, except prefixed by U. Collectively, wchar_t, UTF-16, and UTF-32 string literals are
called wide string literals.
4 The same considerations apply to each element of the sequence in a string literal as if it were in an
integer character constant (for a character or UTF-8 string literal) or a wide character constant (for a
wide string literal), except that the single-quote ’ is representable either by itself or by the escape
sequence \’, but the double-quote " shall be represented by the escape sequence \".
Semantics
5 In translation phase 6, the multibyte character sequences specified by any sequence of adjacent
character and identically-prefixed string literal tokens are concatenated into a single multibyte
character sequence. If any of the tokens has an encoding prefix, the resulting multibyte character
sequence is treated as having the same prefix; otherwise, it is treated as a character string literal.
6 In translation phase 7, a byte or code of value zero is appended to each multibyte character sequence
that results from a string literal or literals. [91] The multibyte character sequence is then used to
initialize an array of static storage duration and length just sufficient to contain the sequence. For
character string literals, the array elements have type char, and are initialized with the individual
bytes of the multibyte character sequence corresponding to the literal encoding (6.2.9). For UTF-8
string literals, the array elements have type char8_t, and are initialized with the characters of the
multibyte character sequence, as encoded in UTF-8. For wide string literals prefixed by the letter
L, the array elements have type wchar_t and are initialized with the sequence of wide characters
corresponding to the wide literal encoding. For wide string literals prefixed by the letter u or U,
the array elements have type char16_t or char32_t, respectively, and are initialized sequence of
wide characters corresponding to UTF-16 and UTF-32 encoded text, respectively. The value of a
string literal containing a multibyte character or escape sequence not represented in the execution
character set is implementation-defined. Any hexadecimal escape sequence or octal escape sequence
specified in a u8, u, or U string specifies a single char8_t, char16_t, or char32_t value and may
result in the full character sequence not being valid UTF-8, UTF-16, or UTF-32.
Footnote 91) A string literal might not be a string (see 7.1.1), because a null character can be embedded in it by a \0 escape sequence.
7 It is unspecified whether these arrays are distinct provided their elements have the appropriate
values. If the program attempts to modify such an array, the behavior is undefined.
8 EXAMPLE 1 This pair of adjacent character string literals
"\x12" "3"
produces a single character string literal containing the two characters whose values are ’\x12’ and ’3’ , because escape
sequences are converted into single members of the execution character set just prior to adjacent string literal concatenation.
9 EXAMPLE 2 Each of the sequences of adjacent string literal tokens
"a" "b" L"c"
"a" L"b" "c"
L"a" "b" L"c"
L"a" L"b" L"c"
is equivalent to the string literal
L"abc"
Likewise, each of the sequences
"a" "b" u"c"
"a" u"b" "c"
u"a" "b" u"c"
u"a" u"b" u"c"
is equivalent to
u"abc"
Forward references: common definitions <stddef.h> (7.21), the mbstowcs function (<IP_ADDRESS>),
Unicode utilities <uchar.h> (7.30).
6.4.6 [Punctuators]
1 Syntax
punctuator: one of
[ ] ( ) { } . ->
++ -- & * + - ~ !
/ % << >> < > <= >= == != ^ | && ||
? : :: ; ...
= *= /= %= += -= <<= >>= &= ^= |=
, # ##
<: :> <% %> %: %:%:
Semantics
2 A punctuator is a symbol that has independent syntactic and semantic significance. Depending on
context, it may specify an operation to be performed (which in turn may yield a value or a function
designator, produce a side effect, or some combination thereof) in which case it is known as an
operator (other forms of operator also exist in some contexts). An operand is an entity on which an
operator acts.
3 In all aspects of the language, the six tokens[92]
<: :> <% %> %: %:%:
behave, respectively, the same as the six tokens
[ ] { } # ##
except for their spelling.[93]
Forward references: expressions (6.5), declarations (6.7), preprocessing directives (6.10), statements
(6.8).
Footnote 92) These tokens are sometimes called "digraphs".
Footnote 93) Thus [ and <: behave differently when "stringized" (see <IP_ADDRESS>), but can otherwise be freely interchanged.
6.4.7 [Header names]
1 Syntax
header-name:
< h-char-sequence >
" q-char-sequence "
h-char-sequence:
h-char
h-char-sequence h-char
h-char:
any member of the source character set except
the new-line character and >
q-char-sequence:
q-char
q-char-sequence q-char
q-char:
any member of the source character set except
the new-line character and "
Semantics
2 The sequences in both forms of header names are mapped in an implementation-defined manner to
headers or external source file names as specified in 6.10.2.
3 If the characters ’ , \ , ", // , or /* occur in the sequence between the < and > delimiters, the behavior
is undefined. Similarly, if the characters ’ , \ , // , or /* occur in the sequence between the "
delimiters, the behavior is undefined.[94] Header name preprocessing tokens are recognized only
within #include preprocessing directives and in implementation-defined locations within #pragma
directives.[95]
Footnote 94) Thus, sequences of characters that resemble escape sequences cause undefined behavior.
Footnote 95) For an example of a header name preprocessing token used in a #pragma directive, see 6.10.10.
4 EXAMPLE The following sequence of characters:
0x3<1/a.h>1e2
#include <1/a.h>
#define const.member@$
forms the following sequence of preprocessing tokens (with each individual preprocessing token delimited by a { on the left
and a } on the right).
{0x3}{<}{1}{/}{a}{.}{h}{>}{1e2}
{#}{include} {<1/a.h>}
{#}{define} {const}{.}{member}{@}{$}
Forward references: source file inclusion (6.10.2).
6.4.8 [Preprocessing numbers]
1 Syntax
pp-number:
digit
. digit
pp-number identifier-continue
pp-number ’ digit
pp-number ’ nondigit
pp-number e sign
pp-number E sign
pp-number p sign
pp-number P sign
pp-number .
Description
2 A preprocessing number begins with a digit optionally preceded by a period (.) and may be followed
by valid identifier characters and the character sequences e+, e-, E+, E-, p+, p-, P+, or P-.
3 Preprocessing number tokens lexically include all floating and integer constant tokens.
Semantics
4 A preprocessing number does not have type or a value; it acquires both after a successful conversion
(as part of translation phase 7) to a floating constant token or an integer constant token.
6.4.9 [Comments]
1 Except within a character constant, a string literal, or a comment, the characters /* introduce a
comment. The contents of such a comment are examined only to identify multibyte characters and
to find the characters */ that terminate it.[96]
Footnote 96) Thus, /
* . . . */ comments do not nest.
2 Except within a character constant, a string literal, or a comment, the characters // introduce a
comment that includes all multibyte characters up to, but not including, the next new-line character.
The contents of such a comment are examined only to identify multibyte characters and to find the
terminating new-line character.
3 EXAMPLE
"a//b" // four-character string literal
#include "//e" // undefined behavior
// */ // comment, not syntax error
f = g/**//h; // equivalent to f = g / h;
//\
i(); // part of a two-line comment
/\
/ j(); // part of a two-line comment
#define glue(x,y) x##y
glue(/,/) k(); // syntax error, not comment
/*//*/ l(); // equivalent to l();
m = n//**/o
+ p; // equivalent to m = n + p;
6.5 [Expressions]
1 An expression is a sequence of operators and operands that specifies computation of a value, or that
designates an object or a function, or that generates side effects, or that performs a combination
thereof. The value computations of the operands of an operator are sequenced before the value
computation of the result of the operator.
2 If a side effect on a scalar object is unsequenced relative to either a different side effect on the
same scalar object or a value computation using the value of the same scalar object, the behavior
is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the
behavior is undefined if such an unsequenced side effect occurs in any of the orderings.[97]
Footnote 97) This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
while allowing
i = i + 1;
a[i] = i;
3 The grouping of operators and operands is indicated by the syntax.[98] Except as specified later, side
effects and value computations of subexpressions are unsequenced.[99]
Footnote 98) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same as the order of the
major subclauses of this subclause, highest precedence first. Thus, for example, the expressions allowed as the operands
of the binary + operator (6.5.6) are those expressions defined in 6.5.1 through 6.5.6. The exceptions are cast expressions
(6.5.4) as operands of unary operators (6.5.3), and an operand contained between any of the following pairs of operators:
grouping parentheses () (6.5.1), subscripting brackets [] (<IP_ADDRESS>), function-call parentheses () (<IP_ADDRESS>), and the conditional
operator ?: (6.5.15).
Within each major subclause, the operators have the same precedence. Left- or right-associativity is indicated in each
subclause by the syntax for the expressions discussed therein.
Footnote 99) In an expression that is evaluated more than once during the execution of a program, unsequenced and indeterminately
sequenced evaluations of its subexpressions need not be performed consistently in different evaluations.
4 Some operators (the unary operator ~ , and the binary operators << , >> , &, ^, and |, collectively
described as bitwise operators) are required to have operands that have integer type. These operators
yield values that depend on the internal representations of integers, and have implementation-
defined and undefined aspects for signed types.
5 If an exceptional condition occurs during the evaluation of an expression (that is, if the result is not
mathematically defined or not in the range of representable values for its type), the behavior is
undefined.
6 The effective type of an object for an access to its stored value is the declared type of the object, if
any.[100] If a value is stored into an object having no declared type through an lvalue having a type
that is not a non-atomic character type, then the type of the lvalue becomes the effective type of the
object for that access and for subsequent accesses that do not modify the stored value. If a value
is copied into an object having no declared type using memcpy or memmove, or is copied as an array
of character type, then the effective type of the modified object for that access and for subsequent
accesses that do not modify the value is the effective type of the object from which the value is
copied, if it has one. For all other accesses to an object having no declared type, the effective type of
the object is simply the type of the lvalue used for the access.
Footnote 100) Allocated objects have no declared type.
7 An object shall have its stored value accessed only by an lvalue expression that has one of the
following types:[101]
— a type compatible with the effective type of the object,
— a qualified version of a type compatible with the effective type of the object,
— a type that is the signed or unsigned type corresponding to the effective type of the object,
— a type that is the signed or unsigned type corresponding to a qualified version of the effective
type of the object,
— an aggregate or union type that includes one of the aforementioned types among its members
(including, recursively, a member of a subaggregate or contained union), or
— a character type.
Footnote 101) The intent of this list is to specify those circumstances in which an object can or cannot be aliased.
8 A floating expression may be contracted, that is, evaluated as though it were a single opera-
tion, thereby omitting rounding errors implied by the source code and the expression evalua-
tion method.[102] The FP_CONTRACT pragma in <math.h> provides a way to disallow contracted
expressions. Otherwise, whether and how expressions are contracted is implementation-defined.[103]
Footnote 102) The intermediate operations in the contracted expression are evaluated as if to infinite range and precision, while the
final operation is rounded to the format determined by the expression evaluation method. A contracted expression might
also omit the raising of floating-point exceptions.
Footnote 103) This license is specifically intended to allow implementations to exploit fast machine instructions that combine multiple
C operators. As contractions potentially undermine predictability, and can even decrease accuracy for containing expressions,
their use needs to be well-defined and clearly documented.
9 Operators involving decimal floating types are evaluated according to the semantics of IEC 60559,
including production of results with the preferred quantum exponent as specified in IEC 60559.
Forward references: the FP_CONTRACT pragma (7.12.2), copying functions (7.26.2).
6.5.1 [Primary expressions]
1 Syntax
primary-expression:
identifier
constant
string-literal
( expression )
generic-selection
Constraints
The identifier in an identifier primary expression shall have a visible declaration as an ordinary
identifier that declares an object or a function[104] .
Semantics
Footnote 104) An identifier designating an enumeration constant is a primary expression through the constant production, not the
identifier production.
2 An identifier primary expression designating an object is an lvalue. An identifier primary expression
designating a function is a function designator.
3 A constant is a primary expression. Its type depends on its form and value, as detailed in 6.4.4.
4 A string literal is a primary expression. It is an lvalue with type as detailed in 6.4.5.
5 A parenthesized expression is a primary expression. Its type, value, and semantics are identical to
those of the unparenthesized expression.
6 A generic selection is a primary expression. Its type, value, and semantics depend on the selected
generic association, as detailed in the following subclause.
Forward references: declarations (6.7).
<IP_ADDRESS> [Generic selection]
1 Syntax
generic-selection:
_Generic ( assignment-expression , generic-assoc-list )
generic-assoc-list:
generic-association
generic-assoc-list , generic-association
generic-association:
type-name : assignment-expression
default : assignment-expression
Constraints
2 A generic selection shall have no more than one default generic association. The type name in a
generic association shall specify a complete object type other than a variably modified type. No two
generic associations in the same generic selection shall specify compatible types. The type of the
controlling expression is the type of the expression as if it had undergone an lvalue conversion,[105]
array to pointer conversion, or function to pointer conversion. That type shall be compatible with at
most one of the types named in the generic association list. If a generic selection has no default
generic association, its controlling expression shall have type compatible with exactly one of the
types named in its generic association list.
Semantics
Footnote 105) An lvalue conversion drops type qualifiers.
3 The controlling expression of a generic selection is not evaluated. If a generic selection has a generic
association with a type name that is compatible with the type of the controlling expression, then the
result expression of the generic selection is the expression in that generic association. Otherwise, the
result expression of the generic selection is the expression in the default generic association. None
of the expressions from any other generic association of the generic selection is evaluated.
4 The type and value of a generic selection are identical to those of its result expression. It is an
lvalue, a function designator, or a void expression if its result expression is, respectively, an lvalue, a
function designator, or a void expression.
5 EXAMPLE The cbrt type-generic macro could be implemented as follows:
#define cbrt(X) _Generic((X), \
long double: cbrtl, \
default: cbrt, \
float: cbrtf \
)(X)
See 7.27 how such a macro could be implemented with the required rounding properties.
6.5.2 [Postfix operators]
1 Syntax
postfix-expression:
primary-expression
postfix-expression [ expression ]
postfix-expression ( argument-expression-listopt )
postfix-expression . identifier
postfix-expression -> identifier
postfix-expression ++
postfix-expression --
compound-literal
argument-expression-list:
assignment-expression
argument-expression-list , assignment-expression
<IP_ADDRESS> [Array subscripting]
1 Constraints
One of the expressions shall have type "pointer to complete object type", the other expression shall
have integer type, and the result has type "type".
Semantics
2 A postfix expression followed by an expression in square brackets [] is a subscripted designation of
an element of an array object. The definition of the subscript operator [] is that E1[E2] is identical
to (*((E1)+(E2))) . Because of the conversion rules that apply to the binary + operator, if E1 is an
array object (equivalently, a pointer to the initial element of an array object) and E2 is an integer,
E1[E2] designates the E2 -th element of E1 (counting from zero).
3 Successive subscript operators designate an element of a multidimensional array object. If E is an
n-dimensional array (n ≥ 2) with dimensions i × j × · · · × k, then E (used as other than an lvalue) is
converted to a pointer to an (n − 1)-dimensional array with dimensions j × · · · × k. If the unary *
operator is applied to this pointer explicitly, or implicitly as a result of subscripting, the result is the
referenced (n − 1)-dimensional array, which itself is converted into a pointer if used as other than an
lvalue. It follows from this that arrays are stored in row-major order (last subscript varies fastest).
4 EXAMPLE Consider the array object defined by the declaration
int x[3][5];
Here x is a 3 × 5 array of objects of type int; more precisely, x is an array of three element objects, each of which is an array of
five objects of type int. In the expression x[i], which is equivalent to (*((x)+(i))) , x is first converted to a pointer to the
initial array of five objects of type int. Then i is adjusted according to the type of x, which conceptually entails multiplying i
by the size of the object to which the pointer points, namely an array of five int objects. The results are added and indirection
is applied to yield an array of five objects of type int. When used in the expression x[i][j], that array is in turn converted
to a pointer to the first of the objects of type int, so x[i][j] yields an int.
Forward references: additive operators (6.5.6), address and indirection operators (<IP_ADDRESS>), array
declarators (<IP_ADDRESS>).
<IP_ADDRESS> [Function calls]
1 Constraints
The expression that denotes the called function[106] shall have type pointer to function returning
void or returning a complete object type other than an array type.
Footnote 106) Most often, this is the result of converting an identifier that is a function designator.
2 The number of arguments shall agree with the number of parameters. Each argument shall have a
type such that its value may be assigned to an object with the unqualified version of the type of its
corresponding parameter
Semantics
3 A postfix expression followed by parentheses () containing a possibly empty, comma-separated
list of expressions is a function call. The postfix expression denotes the called function. The list of
expressions specifies the arguments to the function.
4 An argument may be an expression of any complete object type. In preparing for the call to a
function, the arguments are evaluated, and each parameter is assigned the value of the corresponding
argument.[107]
Footnote 107) A function can change the values of its parameters, but these changes cannot affect the values of the arguments. On the
other hand, it is possible to pass a pointer to an object, and the function can then change the value of the object pointed to. A
parameter declared to have array or function type is adjusted to have a pointer type as described in <IP_ADDRESS>.
5 If the expression that denotes the called function has type pointer to function returning an object
type, the function call expression has the same type as that object type, and has the value determined
as specified in <IP_ADDRESS>. Otherwise, the function call has type void.
6 The arguments are implicitly converted, as if by assignment, to the types of the corresponding
parameters, taking the type of each parameter to be the unqualified version of its declared type. The
ellipsis notation in a function prototype declarator causes argument type conversion to stop after the
last declared parameter, if present. The integer promotions are performed on each trailing argument,
and trailing arguments that have type float are promoted to double. These are called the default
argument promotions. No other conversions are performed implicitly.
7 If the function is defined with a type that is not compatible with the type (of the expression) pointed
to by the expression that denotes the called function, the behavior is undefined.
8 There is a sequence point after the evaluations of the function designator and the actual arguments
but before the actual call. Every evaluation in the calling function (including other function calls)
that is not otherwise specifically sequenced before or after the execution of the body of the called
function is indeterminately sequenced with respect to the execution of the called function.[108]
Footnote 108) In other words, function executions do not "interleave" with each other.
9 Recursive function calls shall be permitted, both directly and indirectly through any chain of other
functions.
10 EXAMPLE In the function call
(*pf[f1()]) (f2(), f3() + f4())
the functions f1, f2, f3, and f4 can be called in any order. All side effects have to be completed before the function pointed
to by pf[f1()] is called.
Forward references: function declarators (<IP_ADDRESS>), function definitions (6.9.1), the return statement
(<IP_ADDRESS>), simple assignment (<IP_ADDRESS>).
<IP_ADDRESS> [Structure and union members]
1 Constraints
The first operand of the . operator shall have an atomic, qualified, or unqualified structure or union
type, and the second operand shall name a member of that type.
2 The first operand of the-> operator shall have type "pointer to atomic, qualified, or unqualified
structure" or "pointer to atomic, qualified, or unqualified union", and the second operand shall
name a member of the type pointed to.
Semantics
3 A postfix expression followed by the . operator and an identifier designates a member of a structure
or union object. The value is that of the named member,[109] and is an lvalue if the first expression is
an lvalue. If the first expression has qualified type, the result has the so-qualified version of the type
of the designated member.
Footnote 109) If the member used to read the contents of a union object is not the same as the member last used to store a value in the
object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new
type as described in 6.2.6 (a process sometimes called "type punning"). This might be a non-value representation.
4 A postfix expression followed by the-> operator and an identifier designates a member of a structure
or union object. The value is that of the named member of the object to which the first expression
points, and is an lvalue.[110] If the first expression is a pointer to a qualified type, the result has the
so-qualified version of the type of the designated member.
Footnote 110) If &E is a valid pointer expression (where & is the "address-of" operator, which generates a pointer to its operand), the
expression (&E)->MOS is the same as E.MOS.
5 Accessing a member of an atomic structure or union object results in undefined behavior.[111]
Footnote 111) For example, a data race would occur if access to the entire structure or union in one thread conflicts with access to a
member from another thread, where at least one access is a modification. Members can be safely accessed using a non-atomic
object which is assigned to or from the atomic object.
6 One special guarantee is made in order to simplify the use of unions: if a union contains several
structures that share a common initial sequence (see below), and if the union object currently contains
one of these structures, it is permitted to inspect the common initial part of any of them anywhere
that a declaration of the completed type of the union is visible. Two structures share a common initial
sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a
sequence of one or more initial members.
7 EXAMPLE 1 If f is a function returning a structure or union, and x is a member of that structure or union, f().x is a valid
postfix expression but is not an lvalue.
8 EXAMPLE 2 In:
struct s { int i; const int ci; };
struct s s;
const struct s cs;
volatile struct s vs;
the various members have the types:
s.i int
s.ci const int
cs.i const int
cs.ci const int
vs.i volatile int
vs.ci volatile const int
9 EXAMPLE 3 The following is a valid fragment:
union {
struct {
int alltypes;
} n;
struct {
int type;
int intnode;
} ni;
struct {
int type;
double doublenode;
} nf;
} u;
u.nf.type = 1;
u.nf.doublenode = 3.14;
/* ... */
if (u.n.alltypes == 1)
if (sin(u.nf.doublenode) == 0.0)
/* ... */
The following is not a valid fragment (because the union type is not visible within function f):
struct t1 { int m; };
struct t2 { int m; };
int f(struct t1 *p1, struct t2 *p2)
{
if (p1->m < 0)
p2->m = -p2->m;
return p1->m;
}
int g()
{
union {
struct t1 s1;
struct t2 s2;
} u;
/* ... */
return f(&u.s1, &u.s2);
}
Forward references: address and indirection operators (<IP_ADDRESS>), structure and union specifiers
(<IP_ADDRESS>).
<IP_ADDRESS> [Postfix increment and decrement operators]
1 Constraints
The operand of the postfix increment or decrement operator shall have atomic, qualified, or unquali-
fied real or pointer type, and shall be a modifiable lvalue.
Semantics
2 The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the
operand object is incremented (that is, the value 1 of the appropriate type is added to it). See the
discussions of additive operators and compound assignment for information on constraints, types,
and conversions and the effects of operations on pointers. The value computation of the result is
sequenced before the side effect of updating the stored value of the operand. With respect to an
indeterminately-sequenced function call, the operation of postfix ++ is a single evaluation. Postfix
++ on an object with atomic type is a read-modify-write operation with memory_order_seq_cst
memory order semantics.[112]
Footnote 112) Where a pointer to an atomic object can be formed and E has integer type, E++ is equivalent to the following code
sequence where T is the type of E:
T *addr = &E;
T old = *addr;
T new;
do {
new = old + 1;
} while (!atomic_compare_exchange_strong(addr, &old, new));
with old being the result of the operation.
Special care is necessary if E has floating type; see <IP_ADDRESS>.
3 The postfix-- operator is analogous to the postfix ++ operator, except that the value of the operand
is decremented (that is, the value 1 of the appropriate type is subtracted from it).
Forward references: additive operators (6.5.6), compound assignment (<IP_ADDRESS>).
<IP_ADDRESS> [Compound literals]
1 Syntax
compound-literal:
( storage-class-specifiersopt type-name ) braced-initializer
storage-class-specifiers:
storage-class-specifier
storage-class-specifiers storage-class-specifier
Constraints
2 The type name shall specify a complete object type or an array of unknown size, but not a variable
length array type.
3 All the constraints for initializer lists in 6.7.10 also apply to compound literals.
4 If the compound literal is evaluated outside the body of a function and outside of any parameter list,
it is associated with file scope; otherwise, it is associated with the enclosing block. Depending on
this association, the storage-class specifiers SC (possibly empty)[113] , type name T, and initializer list,
if any, shall be such that they are valid specifiers for an object definition in file scope or block scope,
respectively, of the following form,
SC typeof(T) ID = { IL };
where ID is an identifier that is unique for the whole program and where IL is a (possibly empty)
initializer list with nested structure, designators, values and types as the initializer list of the
compound literal. All the constraints for storage class specifiers in 6.7.1 also apply correspondingly
to compound literals.
Semantics
Footnote 113) If the storage-class specifiers contain the same storage-class specifier more than once, the following constraint is violated.
5 A compound literal provides an unnamed object whose value, type, storage duration and other
properties are as if given by the definition syntax in the constraints; if the storage duration is
automatic, the lifetime of the instance of the unnamed object is the current execution of the enclosing
block[114] . If the storage-class specifiers contain other specifiers than constexpr, static, register,
or thread_local the behavior is undefined.
Footnote 114) Note that this differs from a cast expression. For example, a cast specifies a conversion to scalar types or void only, and
the result of a cast expression is not an lvalue.
6 The value of the compound literal is that of an lvalue corresponding to the unnamed object.
7 All the semantic rules for initializer lists in 6.7.10 also apply to compound literals[115] .
Footnote 115) For example, subobjects without explicit initializers are initialized to zero.
8 EXAMPLE 1 Consider the following 2 functions:
int f(int*);
int g(char * para[f((int[27]){ 0, })]) {
/* ... */
return 0;
}
Here, each call to g creates an unnamed object of type int[27] to determine the variably-modified type of para for the
duration of the call. During that determination, a pointer to the object is passed into a call to the function f. If a pointer to the
object is kept by f, access to that object is possible during the whole execution of the call to g. The lifetime of the object ends
with the end of the call to g; for any access after that, the behavior is undefined.
9 String literals, and compound literals with const-qualified types, need not designate distinct ob-
jects.[116]
Footnote 116) This allows implementations to share storage for string literals and constant compound literals with the same or
overlapping representations.
10 EXAMPLE 2 The file scope definition
int *p = (int []){2, 4};
initializes p to point to the first element of an array of two ints, the first having the value two and the second, four. The
expressions in this compound literal are required to be constant. The unnamed object has static storage duration.
11 EXAMPLE 3 In contrast, in
void f(void)
{
int *p;
/*...*/
p = (int [2]){*p};
/*...*/
}
p is assigned the address of the first element of an array of two ints, the first having the value previously pointed to by p and
the second, zero. The expressions in this compound literal need not be constant. The unnamed object has automatic storage
duration.
12 EXAMPLE 4 Initializers with designations can be combined with compound literals. Structure objects created using
compound literals can be passed to functions without depending on member order:
drawline((struct point){.x=1, .y=1},
(struct point){.x=3, .y=4});
Or, if drawline instead expected pointers to struct point:
drawline(&(struct point){.x=1, .y=1},
&(struct point){.x=3, .y=4});
13 EXAMPLE 5 A read-only compound literal can be specified through constructions like:
(const float []){1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6}
14 EXAMPLE 6 The following three expressions have different meanings:
"/tmp/fileXXXXXX"
(char []){"/tmp/fileXXXXXX"}
(const char []){"/tmp/fileXXXXXX"}
The first always has static storage duration and has type array of char, but need not be modifiable; the last two have
automatic storage duration when they occur within the body of a function, and the first of these two is modifiable.
15 EXAMPLE 7 Like string literals, const-qualified compound literals can be placed into read-only memory and can even be
shared. For example,
(const char []){"abc"} == "abc"
might yield 1 if the literals’ storage is shared.
16 EXAMPLE 8 Since compound literals are unnamed, a single compound literal cannot specify a circularly linked object. For
example, there is no way to write a self-referential compound literal that could be used as the function argument in place of
the named object endless_zeros below:
struct int_list { int car; struct int_list *cdr; };
struct int_list endless_zeros = {0, &endless_zeros};
eval(endless_zeros);
17 EXAMPLE 9 Each compound literal creates only a single object in a given scope:
struct s { int i; };
int f (void)
{
struct s *p = 0, *q;
int j = 0;
again:
q = p, p = &((struct s){ j++ });
if (j < 2) goto again;
return p == q && q->i == 1;
}
The function f() always returns the value 1.
18 Note that if an iteration statement were used instead of an explicit goto and a label, the lifetime of the unnamed object would
be the body of the loop only, and on entry next time around p would have indeterminate representation, which would result
in undefined behavior.
Forward references: type names (6.7.7), initialization (6.7.10).
6.5.3 [Unary operators]
1 Syntax
unary-expression:
postfix-expression
++ unary-expression
-- unary-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-name )
alignof ( type-name )
unary-operator: one of
& * + - ~ !
<IP_ADDRESS> [Prefix increment and decrement operators]
1 Constraints
The operand of the prefix increment or decrement operator shall have atomic, qualified, or unquali-
fied real or pointer type, and shall be a modifiable lvalue.
Semantics
2 The value of the operand of the prefix ++ operator is incremented. The result is the new value of the
operand after incrementation. The expression ++E is equivalent to (E+=1) . See the discussions of
additive operators and compound assignment for information on constraints, types, side effects,
and conversions and the effects of operations on pointers.
3 The prefix-- operator is analogous to the prefix ++ operator, except that the value of the operand is
decremented.
Forward references: additive operators (6.5.6), compound assignment (<IP_ADDRESS>).
<IP_ADDRESS> [Address and indirection operators]
1 Constraints
The operand of the unary & operator shall be either a function designator, the result of a [] or unary
* operator, or an lvalue that designates an object that is not a bit-field and is not declared with the
register storage-class specifier.
2 The operand of the unary * operator shall have pointer type.
Semantics
3 The unary & operator yields the address of its operand. If the operand has type "type", the result has
type "pointer to type". If the operand is the result of a unary * operator, neither that operator nor
the & operator is evaluated and the result is as if both were omitted, except that the constraints on
the operators still apply and the result is not an lvalue. Similarly, if the operand is the result of a []
operator, neither the & operator nor the unary * that is implied by the [] is evaluated and the result
is as if the & operator were removed and the [] operator were changed to a + operator. Otherwise,
the result is a pointer to the object or function designated by its operand.
4 The unary * operator denotes indirection. If the operand points to a function, the result is a function
designator; if it points to an object, the result is an lvalue designating the object. If the operand has
type "pointer to type", the result has type "type". If an invalid value has been assigned to the pointer,
the behavior of the unary * operator is undefined.[117]
Forward references: storage-class specifiers (6.7.1), structure and union specifiers (<IP_ADDRESS>).
Footnote 117) Thus, & E is equivalent to E (even if E is a null pointer), and &(E1[E2]) to ((E1)+(E2)) . It is always true that if E is a
*
function designator or an lvalue that is a valid operand of the unary & operator, *&E is a function designator or an lvalue
equal to E. If *P is an lvalue and T is the name of an object pointer type, *(T)P is an lvalue that has a type compatible with
that to which T points.
Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an address inappropriately
aligned for the type of object pointed to, and the address of an object after the end of its lifetime.
<IP_ADDRESS> [Unary arithmetic operators]
1 Constraints
The operand of the unary + or- operator shall have arithmetic type; of the ~ operator, integer type;
of the ! operator, scalar type.
Semantics
2 The result of the unary + operator is the value of its (promoted) operand. The integer promotions
are performed on the operand, and the result has the promoted type.
3 The result of the unary- operator is the negative of its (promoted) operand. The integer promotions
are performed on the operand, and the result has the promoted type.
4 The result of the ~ operator is the bitwise complement of its (promoted) operand (that is, each bit in
the result is set if and only if the corresponding bit in the converted operand is not set). The integer
promotions are performed on the operand, and the result has the promoted type. If the promoted
type is an unsigned type, the expression ~E is equivalent to the maximum value representable in
that type minus E.
5 The result of the logical negation operator ! is 0 if the value of its operand compares unequal to
0, 1 if the value of its operand compares equal to 0. The result has type int. The expression !E is
equivalent to (0==E) .
<IP_ADDRESS> [The sizeof and alignof operators]
1 Constraints
The sizeof operator shall not be applied to an expression that has function type or an incomplete
type, to the parenthesized name of such a type, or to an expression that designates a bit-field member.
The alignof operator shall not be applied to a function type or an incomplete type.
Semantics
2 The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the
parenthesized name of a type. The size is determined from the type of the operand. The result
is an integer. If the type of the operand is a variable length array type, the operand is evaluated;
otherwise, the operand is not evaluated and the result is an integer constant.
3 The alignof operator yields the alignment requirement of its operand type. The operand is not
evaluated and the result is an integer constant expression. When applied to an array type, the result
is the alignment requirement of the element type.
4 When sizeof is applied to an operand that has type char, unsigned char, or signed char, (or
a qualified version thereof) the result is 1. When applied to an operand that has array type, the
result is the total number of bytes in the array.[118] When applied to an operand that has structure or
union type, the result is the total number of bytes in such an object, including internal and trailing
padding.
Footnote 118) When applied to a parameter declared to have array or function type, the sizeof operator yields the size of the adjusted
(pointer) type (see 6.9.1).
5 The value of the result of both operators is implementation-defined, and its type (an unsigned
integer type) is size_t, defined in <stddef.h> (and other headers).
6 EXAMPLE 1 A principal use of the sizeof operator is in communication with routines such as storage allocators and I/O
systems. A storage-allocation function might accept a size (in bytes) of an object to allocate and return a pointer to void. For
example:
extern void *alloc(size_t);
double *dp = alloc(sizeof *dp);
The implementation of the alloc function presumably ensures that its return value is aligned suitably for conversion to a
pointer to double.