Стандарт C++ 11 (1119564), страница 26
Текст из файла (страница 26)
Type wchar_t shall have the samesize, signedness, and alignment requirements (3.11) as one of the other integral types, called its underlyingtype. Types char16_t and char32_t denote distinct types with the same size, signedness, and alignment asuint_least16_t and uint_least32_t, respectively, in <stdint.h>, called the underlying types.6Values of type bool are either true or false.47 [ Note: There are no signed, unsigned, short, or longbool types or values. — end note ] Values of type bool participate in integral promotions (4.5).44) that is, large enough to contain any value in the range of INT_MIN and INT_MAX, as defined in the header <climits>.45) See 7.1.6.2 regarding the correspondence between types and the sequences of type-specifiers that designate them.46) This implies that unsigned arithmetic does not overflow because a result that cannot be represented by the resultingunsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by theresulting unsigned integer type.47) Using a bool value in ways described by this International Standard as “undefined,” such as by examining the value of anuninitialized automatic object, might cause it to behave as if it is neither true nor false.§ 3.9.1© ISO/IEC 2011 – All rights reserved75ISO/IEC 14882:2011(E)7Types bool, char, char16_t, char32_t, wchar_t, and the signed and unsigned integer types are collectivelycalled integral types.48 A synonym for integral type is integer type.
The representations of integral typesshall define values by use of a pure binary numeration system.49 [ Example: this International Standardpermits 2’s complement, 1’s complement and signed magnitude representations for integral types. — endexample ]8There are three floating point types: float, double, and long double. The type double provides at leastas much precision as float, and the type long double provides at least as much precision as double.The set of values of the type float is a subset of the set of values of the type double; the set of valuesof the type double is a subset of the set of values of the type long double. The value representation offloating-point types is implementation-defined. Integral and floating types are collectively called arithmetictypes.
Specializations of the standard template std::numeric_limits (18.3) shall specify the maximumand minimum values of each arithmetic type for an implementation.9The void type has an empty set of values. The void type is an incomplete type that cannot be completed. Itis used as the return type for functions that do not return a value. Any expression can be explicitly convertedto type cv void (5.4).
An expression of type void shall be used only as an expression statement (6.2), as anoperand of a comma expression (5.18), as a second or third operand of ?: (5.16), as the operand of typeidor decltype, as the expression in a return statement (6.6.3) for a function with the return type void, or asthe operand of an explicit conversion to type cv void.10A value of type std::nullptr_t is a null pointer constant (4.10).
Such values participate in the pointer andthe pointer to member conversions (4.10, 4.11). sizeof(std::nullptr_t) shall be equal to sizeof(void*).11[ Note: Even if the implementation defines two or more basic types to have the same value representation,they are nevertheless different types. — end note ]3.9.21Compound types[basic.compound]Compound types can be constructed in the following ways:— arrays of objects of a given type, 8.3.4;— functions, which have parameters of given types and return void or references or objects of a giventype, 8.3.5;— pointers to void or objects or functions (including static members of classes) of a given type, 8.3.1;— references to objects or functions of a given type, 8.3.2.
There are two types of references:— lvalue reference— rvalue reference— classes containing a sequence of objects of various types (Clause 9), a set of types, enumerations andfunctions for manipulating these objects (9.3), and a set of restrictions on the access to these entities(Clause 11);— unions, which are classes capable of containing objects of different types at different times, 9.5;— enumerations, which comprise a set of named constant values. Each distinct enumeration constitutesa different enumerated type, 7.2;— pointers to non-static50class members, which identify members of a given type within objects of a48) Therefore, enumerations (7.2) are not integral; however, enumerations can be promoted to integral types as specified in 4.5.49) A positional representation for integers that uses the binary digits 0 and 1, in which the values represented by successivebits are additive, begin with 1, and are multiplied by successive integral power of 2, except perhaps for the bit with the highestposition.
(Adapted from the American National Dictionary for Information Processing Systems.)50) Static class members are objects or functions, and pointers to them are ordinary pointers to objects or functions.§ 3.9.276© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)given class, 8.3.3.2These methods of constructing types can be applied recursively; restrictions are mentioned in 8.3.1, 8.3.4,8.3.5, and 8.3.2.3The type of a pointer to void or a pointer to an object type is called an object pointer type.
[ Note: A pointerto void does not have a pointer-to-object type, however, because void is not an object type. — end note ]The type of a pointer that can designate a function is called a function pointer type. A pointer to objectsof type T is referred to as a “pointer to T.” [ Example: a pointer to an object of type int is referred to as“pointer to int ” and a pointer to an object of class X is called a “pointer to X.” — end example ] Exceptfor pointers to static members, text referring to “pointers” does not apply to pointers to members.
Pointersto incomplete types are allowed although there are restrictions on what can be done with them (3.11).A valid value of an object pointer type represents either the address of a byte in memory (1.7) or a nullpointer (4.10). If an object of type T is located at an address A, a pointer of type cv T* whose value is theaddress A is said to point to that object, regardless of how the value was obtained. [ Note: For instance,the address one past the end of an array (5.7) would be considered to point to an unrelated object of thearray’s element type that might be located at that address.
There are further restrictions on pointers toobjects with dynamic storage duration; see 3.7.4.3. — end note ] The value representation of pointer typesis implementation-defined. Pointers to cv-qualified and cv-unqualified versions (3.9.3) of layout-compatibletypes shall have the same value representation and alignment requirements (3.11). [ Note: Pointers toover-aligned types (3.11) have no special representation, but their range of valid values is restricted by theextended alignment requirement. This International Standard specifies only two ways of obtaining such apointer: taking the address of a valid object with an over-aligned type, and using one of the runtime pointeralignment functions. An implementation may provide other means of obtaining a valid pointer value for anover-aligned type.
— end note ]4A pointer to cv-qualified (3.9.3) or cv-unqualified void can be used to point to objects of unknown type.Such a pointer shall be able to hold any object pointer. An object of type cv void* shall have the samerepresentation and alignment requirements as cv char*.3.9.3CV-qualifiers[basic.type.qualifier]1A type mentioned in 3.9.1 and 3.9.2 is a cv-unqualified type. Each type which is a cv-unqualified completeor incomplete object type or is void (3.9) has three corresponding cv-qualified versions of its type: aconst-qualified version, a volatile-qualified version, and a const-volatile-qualified version. The term objecttype (1.8) includes the cv-qualifiers specified when the object is created. The presence of a const specifierin a decl-specifier-seq declares an object of const-qualified object type; such object is called a const object.The presence of a volatile specifier in a decl-specifier-seq declares an object of volatile-qualified object type;such object is called a volatile object.
The presence of both cv-qualifiers in a decl-specifier-seq declares anobject of const-volatile-qualified object type; such object is called a const volatile object. The cv-qualified orcv-unqualified versions of a type are distinct types; however, they shall have the same representation andalignment requirements (3.9).512A compound type (3.9.2) is not cv-qualified by the cv-qualifiers (if any) of the types from which it is compounded. Any cv-qualifiers applied to an array type affect the array element type, not the array type (8.3.4).3Each non-static, non-mutable, non-reference data member of a const-qualified class object is const-qualified, each non-static, non-reference data member of a volatile-qualified class object is volatile-qualified andsimilarly for members of a const-volatile class.
See 8.3.5 and 9.3.2 regarding function types that havecv-qualifiers.51) The same representation and alignment requirements are meant to imply interchangeability as arguments to functions,return values from functions, and non-static data members of unions.§ 3.9.3© ISO/IEC 2011 – All rights reserved77ISO/IEC 14882:2011(E)4There is a partial ordering on cv-qualifiers, so that a type can be said to be more cv-qualified than another.Table 9 shows the relations that constitute this ordering.Table 9 — Relations on const and volatileno cv-qualifierno cv-qualifierno cv-qualifierconstvolatile5constvolatileconst volatileconst volatileconst volatileIn this International Standard, the notation cv (or cv1, cv2, etc.), used in the description of types, representsan arbitrary set of cv-qualifiers, i.e., one of {const}, {volatile}, {const, volatile}, or the empty set.Cv-qualifiers applied to an array type attach to the underlying element type, so the notation “cv T,” whereT is an array type, refers to an array whose elements are so-qualified.