Alf P. Steinbach wrote:
> The C++ FAQ item 29.5 (this seems to be strongly related to C), at
> <url: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5>
> mentions that
>
> <quote>
> C++ guarantees a char is exactly one byte which is at least 8 bits, short
> is at least 16 bits, int is at least 16 bits, and long is at least 32
> bits.
> </quote>
>
>
> Questions:
>
> (1) This guarantee seems to come from the C standard. Which I don't
> have. Does the C++ standard really guarantee this?
Yes. Also, except where otherwise is stated, C90 is a subset of C++98
standard.
> (2) Is this guarantee originally formulated in terms of number of bits,
> or in terms of e.g. decimal value ranges?
Decimal ranges. C90 defines the following (from the last C90 draft):
"Sizes of integral types <limits.h>
The values given below shall be replaced by constant expressions
suitable for use in #if preprocessing directives. Their
implementation-defined values shall be equal or greater in magnitude
(absolute value) to those shown, with the same sign.
* maximum number of bits for smallest object that is not a bit-field
(byte)
CHAR_BIT 8
* minimum value for an object of type signed char
SCHAR_MIN -127
* maximum value for an object of type signed char
SCHAR_MAX +127
* maximum value for an object of type unsigned char
UCHAR_MAX 255
* minimum value for an object of type char
CHAR_MIN see below
* maximum value for an object of type char
CHAR_MAX see below
* maximum number of bytes in a multibyte character, for any
supported locale
MB_LEN_MAX 1
* minimum value for an object of type short int
SHRT_MIN -32767
* maximum value for an object of type short int
SHRT_MAX +32767
* maximum value for an object of type unsigned short int
USHRT_MAX 65535
* minimum value for an object of type int
INT_MIN -32767
* maximum value for an object of type int
INT_MAX +32767
* maximum value for an object of type unsigned int
UINT_MAX 65535
* minimum value for an object of type long int
LONG_MIN -2147483647
* maximum value for an object of type long int
LONG_MAX +2147483647
* maximum value for an object of type unsigned long int
ULONG_MAX 4294967295
If the value of an object of type char sign-extends when used in
an expression, the value of CHAR_MIN shall be the same as that of
SCHAR_MIN and the value of CHAR_MAX shall be the same as that of
SCHAR_MAX . If the value of an object of type char does not sign-extend
when used in an expression, the value of CHAR_MIN shall be 0 and the
value of CHAR_MAX shall be the same as that of UCHAR_MAX./7/"
> (3) Concerning (2), if formulated in terms of number of bits, are the number
> of bits mentioned simply sizeof(T)*CHAR_BIT, which doesn't say much about
> value ranges, or are they stated to be the value representation bits?
Apart from char, and unsigned char that are guaranteed to not have
padding bits (anyone may tell about signed char?), the number of bits
of a type may contain padding bits etc.
--
Ioannis Vranos
http://www23.brinkster.com/noicys