Vincent Torri <Vincent.Torri@xxxxxxxxxxxxxxx> asks on Mon, 28 Nov 2005 14:24:11 +0100 (CET) about my explanation of the ISO C Standard's minimum requirements on integer type sizes: >> Is there some differences about the size of intrinsic types in C++, >> compared to C ? The 1998 ISO C++ Standard says that its integer types are constrained by limits in <climit>, and that "The contents are the same as the Standard C library header <limits.h>." The 2003 ISO C++ Standard has identical wording. I still have many C++ compilers that haven't reached the 1998 level, and none that claim 2003 conformance. Because the size constraints are minimum requirements, it would be legal for a C++ compiler to make the sizes of its integer types different from those in C compilers on the same system, but doing so would destroy language interoperability, which is far too important: no serious C++ compiler would ever do that. Recall that most, and very possibly, all, C++ compilers still use a large portion of the underlying C libraries (-lc and -lm) at link time. Since I mentioned Fortran briefly in my earlier posting, it is worth remarking that Java, which shares a good deal of syntax, and heritage, with C, is based on an underlying precisely-specified virtual machine. It consequently has exact host-platform-independent range requirements on its byte, short, int, and long data types (8, 16, 32, and 64 bits, respectively), and requires that char be an unsigned 16-bit type. See section 4.2 of @String{pub-AW = "Ad{\-d}i{\-s}on-Wes{\-l}ey"} @String{pub-AW:adr = "Reading, MA, USA"} @Book{Gosling:2000:JLS, author = "James Gosling and Bill Joy and Guy L. Steele and Gilad Bracha", title = "The {Java} language specification", publisher = pub-AW, address = pub-AW:adr, edition = "Second", pages = "xxv + 505", year = "2000", ISBN = "0-201-31008-2", ISBN-13 = "978-0-201-31008-5", LCCN = "QA76.73.J38 G68 2000", bibdate = "Tue Feb 20 18:39:03 MST 2001", series = "Java series", URL = "http://java.sun.com/people/jag/", acknowledgement = ack-nhfb, keywords = "java (computer program language)", } Because of the platform-dependence of the sizes of the C integer data types, the 1999 ISO C Standard introduced new types that provide guarantees on minimum sizes: >> ... >> 7.18.1.1 Exact-width integer types >> >> 1 The typedef name intN_t designates a signed integer type with width >> N , no padding bits, and a two's complement representation. Thus, >> int8_t denotes a signed integer type with a width of exactly 8 >> bits. >> >> 2 The typedef name uintN_t designates an unsigned integer type with >> width N . Thus, uint24_t denotes an unsigned integer type with a >> width of exactly 24 bits. >> >> 3 These types are optional. However, if an implementation provides >> integer types with widths of 8, 16, 32, or 64 bits, it shall >> define the corresponding typedef names. >> >> 7.18.1.2 Minimum-width integer types >> >> 1 The typedef name int_leastN_t designates a signed integer type with >> a width of at least N , such that no signed integer type with >> lesser size has at least the specified width. Thus, >> int_least32_t denotes a signed integer type with a width of at >> least 32 bits. >> >> 2 The typedef name uint_leastN_t designates an unsigned integer type >> with a width of at least N , such that no unsigned integer type >> with lesser size has at least the specified width. Thus, >> uint_least16_t denotes an unsigned integer type with a width of >> at least 16 bits. >> >> 3 The following types are required: >> >> int_least8_t uint_least8_t >> int_least16_t uint_least16_t >> int_least32_t uint_least32_t >> int_least64_t uint_least64_t >> >> All other types of this form are optional. >> ... C99 also provides the intmax_t and uintmax_t types, corresponding to the largest size. Since there are still plenty of C compilers that conform only to the earlier ISO 1989 C Standard, it is not yet portable to use these new datatypes, at least not without a fallback that supplies suitable type definitions when they are not provided by the compiler. ------------------------------------------------------------------------------- - Nelson H. F. Beebe Tel: +1 801 581 5254 - - University of Utah FAX: +1 801 581 4148 - - Department of Mathematics, 110 LCB Internet e-mail: beebe@xxxxxxxxxxxxx - - 155 S 1400 E RM 233 beebe@xxxxxxx beebe@xxxxxxxxxxxx - - Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe - -------------------------------------------------------------------------------