|
4165 | 4165 | \rSec2[basic.fundamental]{Fundamental types}
|
4166 | 4166 |
|
4167 | 4167 | \pnum
|
4168 |
| -\indextext{type!integral}% |
4169 |
| -\indextext{floating-point type|see{type, floating-point}}% |
4170 | 4168 | \indextext{type!implementation-defined \tcode{sizeof}}%
|
4171 |
| -\indextext{type!Boolean}% |
4172 |
| -\indextext{type!\idxcode{char}}% |
4173 |
| -\indextext{type!character}% |
4174 |
| -Objects declared as characters (\tcode{char}) shall be large enough to |
4175 |
| -store any member of the implementation's basic character set. If a |
4176 |
| -character from this set is stored in a character object, the integral |
4177 |
| -value of that character object is equal to the value of the single |
4178 |
| -character literal form of that character. It is \impldef{signedness of \tcode{char}} |
4179 |
| -whether a \tcode{char} object can hold negative values. |
4180 |
| -\indextext{\idxcode{char}!implementation-defined sign of}% |
4181 |
| -\indextext{type!\idxcode{signed char}}% |
4182 |
| -\indextext{type!\idxcode{unsigned char}}% |
4183 |
| -Characters can be explicitly declared \tcode{unsigned} or |
4184 |
| -\tcode{signed}. |
4185 |
| -\indextext{character!\idxcode{signed}}% |
4186 |
| -Plain \tcode{char}, \tcode{signed char}, and \tcode{unsigned char} are |
4187 |
| -three distinct types, collectively called |
4188 |
| -\defnx{narrow character types}{type!narrow character}. |
4189 |
| -A \tcode{char}, a \tcode{signed char}, and an |
4190 |
| -\tcode{unsigned char} occupy the same amount of storage and have the |
4191 |
| -same alignment requirements\iref{basic.align}; that is, they have the |
4192 |
| -same object representation. For narrow character types, all bits of the object |
4193 |
| -representation participate in the value representation. |
4194 |
| -\begin{note} |
4195 |
| -A bit-field of narrow character type whose length is larger than |
4196 |
| -the number of bits in the object representation of that type has |
4197 |
| -padding bits; see~\ref{basic.types}. |
4198 |
| -\end{note} |
4199 |
| -For unsigned narrow |
4200 |
| -character types, each possible bit pattern of the value representation |
4201 |
| -represents a distinct number. These requirements do not hold for other types. In |
4202 |
| -any particular implementation, a plain \tcode{char} object can take on |
4203 |
| -either the same values as a \tcode{signed char} or an \tcode{unsigned |
4204 |
| -char}; which one is \impldef{representation of \tcode{char}}. |
4205 |
| -For each value \placeholder{i} of type \tcode{unsigned char} in the range |
4206 |
| -0 to 255 inclusive, there exists a value \placeholder{j} of type |
4207 |
| -\tcode{char} such that the result of an integral |
4208 |
| -conversion\iref{conv.integral} from \placeholder{i} to \tcode{char} is |
4209 |
| -\placeholder{j}, and the result of an integral conversion from |
4210 |
| -\placeholder{j} to \tcode{unsigned char} is \placeholder{i}. |
4211 |
| - |
4212 |
| -\pnum |
4213 | 4169 | \indextext{type!standard signed integer}%
|
4214 | 4170 | There are five \defnx{standard signed integer types}{standard signed integer type} :
|
4215 | 4171 | \indextext{type!\idxcode{signed char}}%
|
|
4225 | 4181 | \indextext{type!signed integer}%
|
4226 | 4182 | There may also be \impldef{extended signed integer types}
|
4227 | 4183 | \defnx{extended signed integer types}{extended signed integer type}.
|
4228 |
| -The standard and |
4229 |
| -extended signed integer types are collectively called |
| 4184 | +The standard and extended signed integer types are collectively called |
4230 | 4185 | \defnx{signed integer types}{signed integer type}.
|
| 4186 | +The range of representable values for a signed integer type is |
| 4187 | +$-2^{N-1}$ to $2^{N-1}-1$ (inclusive), |
| 4188 | +where \placeholder{N} is called the \defn{range exponent} of the type. |
4231 | 4189 | \indextext{integral type!implementation-defined \tcode{sizeof}}%
|
4232 | 4190 | \begin{note}
|
4233 |
| -Plain \tcode{int}s |
4234 |
| -are intended to have |
4235 |
| -the natural size suggested by the architecture of the |
4236 |
| -execution environment; |
| 4191 | +Plain \tcode{int}s are intended to have |
| 4192 | +the natural size suggested by the architecture of the execution environment; |
4237 | 4193 | the other signed integer types are provided to meet special needs.
|
4238 | 4194 | \end{note}
|
4239 | 4195 |
|
4240 | 4196 | \pnum
|
4241 | 4197 | \indextext{type!\idxcode{unsigned}}%
|
| 4198 | +\indextext{type!unsigned integer}% |
4242 | 4199 | For each of the standard signed integer types,
|
4243 | 4200 | there exists a corresponding (but different)
|
4244 | 4201 | \indextext{type!standard unsigned integer}%
|
|
4250 | 4207 | \indextext{type!\idxcode{unsigned long long}}%
|
4251 | 4208 | ``\tcode{unsigned char}'', ``\tcode{unsigned short int}'',
|
4252 | 4209 | ``\tcode{unsigned int}'', ``\tcode{unsigned long int}'', and
|
4253 |
| -``\tcode{unsigned long long int}'', each of |
4254 |
| -which occupies the same amount of storage and has the same alignment |
4255 |
| -requirements\iref{basic.align} as the corresponding signed integer |
4256 |
| -type\footnote{See~\ref{dcl.type.simple} regarding the correspondence between types and |
4257 |
| -the sequences of \grammarterm{type-specifier}{s} that designate them.}; |
4258 |
| -that is, each signed integer type has the same object representation as |
4259 |
| -its corresponding unsigned integer type. |
| 4210 | +``\tcode{unsigned long long int}''. |
4260 | 4211 | \indextext{type!extended unsigned integer}%
|
4261 |
| -\indextext{type!unsigned integer}% |
4262 |
| -Likewise, for each of the extended signed integer types there exists a |
4263 |
| -corresponding |
4264 |
| -\defn{extended unsigned integer type} with the same amount of storage and alignment |
4265 |
| -requirements. The standard and extended unsigned integer types are |
4266 |
| -collectively called \defnx{unsigned integer types}{unsigned integer type}. The range of non-negative |
4267 |
| -values of a signed integer type is |
4268 |
| -a subrange of the corresponding unsigned integer type, |
4269 |
| -the representation of the same value in each of the two types is the same, and |
4270 |
| -the value representation of each corresponding signed/unsigned type shall be the same. |
| 4212 | +Likewise, for each of the extended signed integer types, |
| 4213 | +there exists a corresponding \defn{extended unsigned integer type}. |
| 4214 | +The standard and extended unsigned integer types |
| 4215 | +are collectively called \defnx{unsigned integer types}{unsigned integer type}. |
| 4216 | +An unsigned integer type has the same range exponent \placeholder{N} |
| 4217 | +as the corresponding signed integer type. |
| 4218 | +\indextext{arithmetic!\idxcode{unsigned}}% |
| 4219 | +The range of representable values for the unsigned type is |
| 4220 | +$0$ to $2^N-1$ (inclusive); |
| 4221 | +arithmetic for the unsigned type is performed modulo $2^N$. |
| 4222 | +\begin{note} |
| 4223 | +Unsigned arithmetic does not overflow. |
| 4224 | +Overflow for signed arithmetic yields undefined behavior\iref{expr.pre}. |
| 4225 | +\end{note} |
| 4226 | + |
| 4227 | +\pnum |
| 4228 | +\indextext{signed integer representation!two's complement}% |
| 4229 | +An unsigned integer type has the same |
| 4230 | +object representation, |
| 4231 | +value representation, and |
| 4232 | +alignment requirements\iref{basic.align} |
| 4233 | +as the corresponding signed integer type. |
| 4234 | +For each value $x$ of a signed integer type, |
| 4235 | +the value of the corresponding unsigned integer type |
| 4236 | +congruent to $x$ modulo $2^N$ has the same value |
| 4237 | +of corresponding bits in its value representation.\footnote{This |
| 4238 | +is also known as two's complement representation.} |
| 4239 | +\begin{example} |
| 4240 | +The value $-1$ of a signed integer type has the same representation as |
| 4241 | +the largest value of the corresponding unsigned type. |
| 4242 | +\end{example} |
| 4243 | + |
| 4244 | +\begin{floattable}{Minimum range exponent}{tab:range.exponent}{ll} |
| 4245 | +\topline |
| 4246 | +\lhdr{Type} & \rhdr{Minimum range exponent $N$} \\ |
| 4247 | +\capsep |
| 4248 | +\tcode{signed char} & 8 \\ |
| 4249 | +\tcode{short} & 16 \\ |
| 4250 | +\tcode{int} & 16 \\ |
| 4251 | +\tcode{long} & 32 \\ |
| 4252 | +\tcode{long long} & 64 \\ |
| 4253 | +\end{floattable} |
| 4254 | + |
| 4255 | +\pnum |
| 4256 | +The range exponent of each signed integer type |
| 4257 | +shall not be less than the values specified in \tref{range.exponent}. |
| 4258 | +The value representation of a signed or unsigned integer type |
| 4259 | +comprises $N$ bits, where N is the respective range exponent. |
| 4260 | +Each set of values for any padding bits\iref{basic.types} |
| 4261 | +in the object representation are |
| 4262 | +alternative representations of the value specified by the value representation. |
| 4263 | +\begin{note} |
| 4264 | +Padding bits have unspecified value, but do not cause traps. |
| 4265 | +See also ISO C 6.2.6.2. |
| 4266 | +\end{note} |
| 4267 | +\begin{note} |
| 4268 | +The signed and unsigned integer types satisfy |
| 4269 | +the constraints given in ISO C 5.2.4.2.1. |
| 4270 | +\end{note} |
| 4271 | +Except as specified above, |
| 4272 | +the range exponent of a signed or unsigned integer type is |
| 4273 | +\impldef{range exponent of integral type}. |
| 4274 | + |
| 4275 | +\pnum |
| 4276 | +Each value $x$ of an unsigned integer type with range exponent $N$ has |
| 4277 | +a unique representation $x = x_0 2^0 + x_1 2^1 + \ldots + x_{N-1} 2^{N-1}$, |
| 4278 | +where each coefficient $x_i$ is either 0 or 1; |
| 4279 | +this is called the \defn{base-2 representation} of $x$. |
| 4280 | +The base-2 representation of a value of signed integer type is |
| 4281 | +the base-2 representation of the congruent value |
| 4282 | +of the corresponding unsigned integer type. |
4271 | 4283 | \indextext{type!standard integer}%
|
4272 | 4284 | \indextext{type!extended integer}%
|
4273 | 4285 | The standard signed integer types and standard unsigned integer types
|
4274 | 4286 | are collectively called the \defnx{standard integer types}{standard integer type}, and the extended
|
4275 | 4287 | signed integer types and extended
|
4276 | 4288 | unsigned integer types are collectively called the
|
4277 | 4289 | \defnx{extended integer types}{extended integer type}.
|
4278 |
| -The signed and unsigned integer types shall satisfy |
4279 |
| -the constraints given in the C standard, subclause 5.2.4.2.1. |
4280 | 4290 |
|
4281 | 4291 | \pnum
|
4282 |
| -\indextext{arithmetic!\idxcode{unsigned}}% |
4283 |
| -Unsigned integers shall obey the laws of arithmetic modulo $2^n$ where $n$ is |
4284 |
| -the number of bits in the value representation of that particular size of |
4285 |
| -integer.\footnote{This implies that |
4286 |
| -unsigned arithmetic does not overflow because a result |
4287 |
| -that cannot be represented by the resulting unsigned integer type is |
4288 |
| -reduced modulo the number that is one greater than the largest value |
4289 |
| -that can be represented by the resulting unsigned integer type.} |
| 4292 | +A fundamental type specified to have |
| 4293 | +a signed or unsigned integer type as its \defn{underlying type} has |
| 4294 | +the same object representation, |
| 4295 | +value representation, |
| 4296 | +alignment requirements\iref{basic.align}, and |
| 4297 | +range of representable values as the underlying type. |
| 4298 | +Further, each value has the same representation in both types. |
| 4299 | + |
| 4300 | +\pnum |
| 4301 | +\indextext{type!\idxcode{char}}% |
| 4302 | +\indextext{type!character}% |
| 4303 | +\indextext{type!narrow character}% |
| 4304 | +\indextext{\idxcode{char}!implementation-defined sign of}% |
| 4305 | +\indextext{type!\idxcode{signed char}}% |
| 4306 | +\indextext{character!\idxcode{signed}}% |
| 4307 | +\indextext{type!\idxcode{unsigned char}}% |
| 4308 | +Type \tcode{char} is a distinct type |
| 4309 | +that has an \impldef{underlying type of \tcode{char}} choice of |
| 4310 | +``\tcode{signed char}'' or ``\tcode{unsigned char}'' as its underlying type. |
| 4311 | +The values of type \tcode{char} can represent distinct codes |
| 4312 | +for all members of the implementation's basic character set. |
| 4313 | +The three types \tcode{char}, \tcode{signed char}, and \tcode{unsigned char} |
| 4314 | +are collectively called \defnx{narrow character types}{narrow character type}. |
| 4315 | +For narrow character types, |
| 4316 | +each possible bit pattern of the object representation represents |
| 4317 | +a distinct value. |
| 4318 | +\begin{note} |
| 4319 | +This requirement does not hold for other types. |
| 4320 | +\end{note} |
| 4321 | +\begin{note} |
| 4322 | +A bit-field of narrow character type whose width is larger than |
| 4323 | +the range exponent of that type has padding bits; see \ref{basic.types}. |
| 4324 | +\end{note} |
4290 | 4325 |
|
4291 | 4326 | \pnum
|
| 4327 | +\indextext{\idxcode{wchar_t}|see{type, \tcode{wchar_t}}}% |
| 4328 | +\indextext{type!\idxcode{wchar_t}}% |
| 4329 | +\indextext{underlying type|see{type, underlying}}% |
| 4330 | +\indextext{type!underlying!\idxcode{wchar_t}}% |
| 4331 | +Type \tcode{wchar_t} is a distinct type that has |
| 4332 | +an \impldef{underlying type of \tcode{wchar_t}} |
| 4333 | +signed or unsigned integer type as its underlying type. |
| 4334 | +The values of type \tcode{wchar_t} can represent |
| 4335 | +distinct codes for all members of the largest extended character set |
| 4336 | +specified among the supported locales\iref{locale}. |
4292 | 4337 | \indextext{\idxcode{char16_t}|see{type, \tcode{char16_t}}}%
|
4293 | 4338 | \indextext{\idxcode{char32_t}|see{type, \tcode{char32_t}}}%
|
4294 |
| -\indextext{\idxcode{wchar_t}|see{type, \tcode{wchar_t}}}% |
4295 | 4339 | \indextext{type!\idxcode{char16_t}}%
|
4296 | 4340 | \indextext{type!\idxcode{char32_t}}%
|
4297 |
| -\indextext{type!\idxcode{wchar_t}}% |
4298 |
| -\indextext{underlying type|see{type, underlying}}% |
4299 | 4341 | \indextext{type!underlying!\idxcode{char16_t}}%
|
4300 | 4342 | \indextext{type!underlying!\idxcode{char32_t}}%
|
4301 |
| -Type \tcode{wchar_t} is a distinct type whose values can represent |
4302 |
| -distinct codes for all members of the largest extended character set |
4303 |
| -specified among the supported locales\iref{locale}. Type |
4304 |
| -\tcode{wchar_t} shall have the same size, signedness, and alignment |
4305 |
| -requirements\iref{basic.align} as one of the other integral types, |
4306 |
| -called its \defnx{underlying type}{type!underlying!\idxcode{wchar_t}}. Types \tcode{char16_t} and |
4307 |
| -\tcode{char32_t} denote distinct types with the same size, signedness, |
4308 |
| -and alignment as \tcode{uint_least16_t} and \tcode{uint_least32_t}, |
4309 |
| -respectively, in \tcode{<cstdint>}, called the underlying types. |
| 4343 | +Types \tcode{char16_t} and \tcode{char32_t} denote distinct types |
| 4344 | +whose underlying types are \tcode{uint_least16_t} and \tcode{uint_least32_t}, |
| 4345 | +respectively, in \tcode{<cstdint>}. |
4310 | 4346 |
|
4311 | 4347 | \pnum
|
4312 | 4348 | \indextext{Boolean type}%
|
4313 |
| -Values of type \tcode{bool} are either \tcode{true} or |
4314 |
| -\tcode{false}.\footnote{Using a \tcode{bool} value in ways described by this document |
4315 |
| -as ``undefined'', such as by examining the value of an |
4316 |
| -uninitialized automatic object, might cause it to behave as if it is |
4317 |
| -neither \tcode{true} nor \tcode{false}.} |
4318 |
| -\begin{note} There are no \tcode{signed}, \tcode{unsigned}, \tcode{short}, |
4319 |
| -or \tcode{long bool} types or values. \end{note} Values of type |
4320 |
| -\tcode{bool} participate in integral promotions\iref{conv.prom}. |
| 4349 | +\indextext{type!Boolean}% |
| 4350 | +Type \tcode{bool} is a distinct type that has |
| 4351 | +the same object representation, |
| 4352 | +value representation, and |
| 4353 | +alignment requirements as |
| 4354 | +an \impldef{underlying type of \tcode{bool}} unsigned integer type. |
| 4355 | +The values of type \tcode{bool} are |
| 4356 | +\tcode{true} and \tcode{false}.\footnote{Using a \tcode{bool} value |
| 4357 | +in ways described by this document as ``undefined'', |
| 4358 | +such as by examining the value of an uninitialized automatic object, |
| 4359 | +might cause it to behave as if it is neither \tcode{true} nor \tcode{false}.} |
| 4360 | +\begin{note} |
| 4361 | +There are no \tcode{signed}, \tcode{unsigned}, |
| 4362 | +\tcode{short}, or \tcode{long bool} types or values. |
| 4363 | +\end{note} |
4321 | 4364 |
|
4322 | 4365 | \pnum
|
| 4366 | +\indextext{type!integral}% |
4323 | 4367 | Types \tcode{bool}, \tcode{char}, \tcode{char16_t}, \tcode{char32_t},
|
4324 | 4368 | \tcode{wchar_t}, and the signed and unsigned integer types are
|
4325 | 4369 | collectively called
|
4326 |
| -\defnx{integral}{integral type} types.\footnote{Therefore, enumerations\iref{dcl.enum} are not integral; however, |
4327 |
| -enumerations can be promoted to integral types as specified |
4328 |
| -in~\ref{conv.prom}.} |
4329 |
| -A synonym for integral type is |
4330 |
| -\indextext{signed integer representation!ones' complement}% |
4331 |
| -\indextext{signed integer representation!two's complement}% |
4332 |
| -\indextext{signed integer representation!signed magnitude}% |
4333 |
| -\defn{integer type}. The representations of integral types shall |
4334 |
| -define values by use of a pure binary numeration system.\footnote{A positional |
4335 |
| -representation for integers that uses the binary digits 0 |
4336 |
| -and 1, in which the values represented by successive bits are additive, |
4337 |
| -begin with 1, and are multiplied by successive integral power of 2, |
4338 |
| -except perhaps for the bit with the highest position. (Adapted from the |
4339 |
| -\doccite{American National Dictionary for Information Processing Systems}.)} |
4340 |
| -\begin{example} This document permits two's complement, |
4341 |
| -ones' complement and signed magnitude representations for integral types. |
4342 |
| -\end{example} |
| 4370 | +\defnx{integral types}{integral type}. |
| 4371 | +A synonym for integral type is \defn{integer type}. |
| 4372 | +\begin{note} |
| 4373 | +Enumerations\iref{dcl.enum} are not integral; |
| 4374 | +however, unscoped enumerations can be promoted to integral types |
| 4375 | +as specified in \ref{conv.prom}. |
| 4376 | +\end{note} |
4343 | 4377 |
|
4344 | 4378 | \pnum
|
| 4379 | +\indextext{floating-point type|see{type, floating-point}}% |
4345 | 4380 | There are three \defnx{floating-point types}{type!floating-point}:
|
4346 | 4381 | \indextext{type!\idxcode{float}}%
|
4347 | 4382 | \tcode{float},
|
|
0 commit comments