Sorry, I sent this to comp.std.c++ and meant to send it here as well...
Why are the minimum size guarantees for fundamental types intentionally
omitted from section 3.9.1 Fundamental types of the C++ standard? If indeed
these guarantees can be inferred from other parts of the standard, and it is
the intent of the standards committee that these guarantees exist, then why
are they not listed in the most relevant section?
I've been sorting through my reference material to find exactly how these
minimum size requirements can be inferred from the C++ standard. Listed
below is what I've come up with... unfortunately, given the references
within the standard, I cannot deduce what Stroustrup says in the following
second quote.
Sroustrup says the following in The C++ Programming Language Third Edition
on page seventy-five in section 4.6 Sizes:
"1 = sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)"
"In addition, it is guaranteed that a char has at least 8 bits, a short at
least 16 bits, and a long at least 32 bits."
The C++ faq lite agrees with this:
http://www.parashift.com/c++-faq-lit....html#faq-29.5
"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."
Harbison and Steele, in C A Reference Manual Fourth Edition, in section
5.1.1 Signed Integer Types, say the following:
"The C language does not specify the range of integers that the integral
types will represent, except to say that type int may not be smaller than
short and long may not be smaller than int. Many implementations represent
characters in 8 bits, type short in 16 bits, and type long in 32 bits, with
type int using either 16 or 32 bits depending on the implementation. ISO C
requires implementations to use at least these widths."
From what I can see in the standard,
3.9.1.2: "There are four signed integer types: "signed char", "short int",
"int", and "long int." In this list, each type provides at least as much
storage as those preceding it in the list. Plain ints have the natural size
suggested by the architecture of the execution environment (39); the other
signed integer types are provided to meet special needs." Where (39) says,
"that is, large enough to contain any value in the range of INT_MIN and
INT_MAX, as defined in the header <climits>."
18.2.2.1 Header <climits>. This section lists a table of defined constants
for various min/max values for types; however, the values are omitted.
18.2.2.2 "The contents are the same as the Standard C library header
<limits.h>."
Annex D D.5.1 Standard C library headers lists a table of C Headers, which
includes <limits.h>.
Please, can someone help explain this by providing the relevant quotes from
the C++ standard? I originally created a thread for this issue in
comp.lang.c++ and received reply from John Carson suggesting that it may be
inherited from C. Harbison and Steele claim that these guarantees do exist
in the C standard. I do not have a copy of the C standard, so I cannot
check that. If this is the case, it is my belief that this information
should be explicitly stated in the C++ standard as well. I'm going to send
this to comp.lang.c++, too, so sorry for the duplicate thread.
I want to add that I've seen many times that people "refer to the standard"
as the authoritative reference on things related to C++. I'd like to be
able to do this, and have tried -- unsuccessfully in this case. For those
people that do often refer to the standard, hopefully you can help me with
how to find what I want from the standard. In this case, I believe I looked
in the relevant sections and followed up on cross-references within the
standard. Does it really have to be so difficult to find something that
could so easily be stated in the relevant section? If nothing else, insert
the quote from Stroustrup's book,
"In addition, it is guaranteed that a char has at least 8 bits, a short at
least 16 bits, and a long at least 32 bits."
Thanks,
Kyle