Unless I am switching back and forth between compilers often, I tend to need a kick (or look up) to recall the different implementations of integer types.
The below page of Jack Klein's is just that kick.
Integer Types In C and C++
The introduction, a copy-paste from the above site, and the sample program to run through your compiler is below.
IntroductionYou would think that the basic integer types provided by the C and C++ languages wouldn't cause an much confusion as they do. Almost every day there are posts in the C and C++ newsgroups which show that many newcomers do not understand them. Some experienced programmers who are only familiar with one platform do not understand them either.
The most common source of confusion are the sizes of the integer types, and the range of values which they can hold. That is because the languages leave many features of the integer types implementation-defined, meaning that it is up to the particular compiler to determine their exact specifications. C and C++ do set minimum requirements for each of the integer types, but the compiler is free to exceed these limits.
Each compiler is required to document its implementation. This information should be available in the printed manuals, online help, or man pages which come with the compiler.
In addition, there is a required standard header named <limits.h> (<climits> in newer C++ compilers) that provides information about the integer types that can be used in your programs at run time. A compiler is not required to provide a header like <limits.h> as a readable text file, but I do not know of any compilers which do not.
There are programs on this page to display the information that this file contains.
A Program To Display Integer Type Information Standard C++ Compilers
volatile int char_min = CHAR_MIN;
cout << "Size of boolean type is "
<< sizeof(bool) << " byte(s)"
cout << "Number of bits in a character: "
<< CHAR_BIT << '\n';
cout << "Size of character types is "
<< " byte" << '\n';
cout << "Signed char min: "
<< SCHAR_MIN << " max: "
cout << "Unsigned char min: 0 max: "
<< UCHAR_MAX << '\n';
cout << "Default char is ";
if (char_min < 0)
cout << "signed";
else if (char_min == 0)
cout << "unsigned";
cout << "non-standard";
cout << "\n\n";
cout << "Size of short int types is "
<< sizeof(short) << " bytes"
cout << "Signed short min: "
<< SHRT_MIN << " max: "
<< SHRT_MAX << '\n';
cout << "Unsigned short min: 0 max: "
<< USHRT_MAX << "\n\n";
cout << "Size of int types is "
<< sizeof(int) << " bytes"
cout << "Signed int min: "
<< INT_MIN << " max: "
<< INT_MAX << '\n';
cout << "Unsigned int min: 0 max: "
<< UINT_MAX << "\n\n";
cout << "Size of long int types is "
<< sizeof(long) << " bytes"
cout << "Signed long min: " <<
LONG_MIN << " max: "
<< LONG_MAX << '\n';
cout << "Unsigned long min: 0 max: "
<< ULONG_MAX << endl;
Keywords: C++, types, integer, int, short, long, char, bool, sizeof, C, compiler implementation of integer types, unsigned.