Let's have a thread filled with handy-dandy C++ tutorials, since several people seem to be interested in learning modern, Standard C++.
Integer Data Types
C++ has lots of integer data types, and it can get pretty confusing.
char - This type (I pronounce it "care" as in character; infidels say "char" as in charred, or "car" as in Porsche) is guaranteed to be at least 8 bits long, but may be more. On most systems, it really is 8 bits. char alone among the integral data types may be signed or unsigned, depending on the implementation. You must explicitly request "signed char" or "unsigned char" if you want to be sure. In C++, character constants like 'q' have type char, but char is not special - it's just a narrow integer type.
In C++, a char is a byte, just not necessarily an octet. sizeof reports sizes in bytes, so sizeof(char) is always and forever 1.
short - Guaranteed to be at least 16 bits. On most systems it really is 16 bits. short, like all other integral data types except for char, is by default signed.
int - Guaranteed to be at least 16 bits, and no shorter than short. On most systems is really is 32 bits (true on basically every x86, x86-64, and IA-64 compiler today).
long - Guaranteed to be at least 32 bits, and no shorter than int. long is generally 32 bits on 32-bit systems and 64-bits on 64-bit systems (on x86-64 and IA-64, this is true).
long long - Not a part of the 2003 C++ Standard, but I use it anyways (it will be a part of the next C++ Standard, and is a part of the 1999 C Standard). Guaranteed to be at least 64 bits. Currently, this holds on most systems.
size_t - This is a typedef from <cstddef> which is guaranteed to be the type that sizeof returns. It is a type suitable for holding the size of an array, and is always unsigned.
Now, isn't that nice and confusing? Boost provides <boost/cstddef.hpp>, which has helpful typedefs from the 1999 C Standard that aren't yet in some C++ compilers. boost::uint8_t is guaranteed to be an unsigned 8 bit type (if the compiler provides one), and similarly for boost::uint64_t, etc.
I have found that in writing portable code, having guaranteed fixed-width datatypes is very important, so that the code will have the same meaning whether compiled on 32-bit or 64-bit systems. Therefore, I typedef the boost/cstddef.hpp types to my own, shorter names:
uc_t, us_t, ul_t, ull_t - unsigned 8, 16, 32, 64 bit types
sc_t, ss_t, sl_t, sll_t - signed 8, 16, 32, 64 bit types
My code isn't 64-bit clean yet, but it's getting there.
I think I'll follow up with a Standard Template Library tutorial later.
Integer Data Types
C++ has lots of integer data types, and it can get pretty confusing.
char - This type (I pronounce it "care" as in character; infidels say "char" as in charred, or "car" as in Porsche) is guaranteed to be at least 8 bits long, but may be more. On most systems, it really is 8 bits. char alone among the integral data types may be signed or unsigned, depending on the implementation. You must explicitly request "signed char" or "unsigned char" if you want to be sure. In C++, character constants like 'q' have type char, but char is not special - it's just a narrow integer type.
In C++, a char is a byte, just not necessarily an octet. sizeof reports sizes in bytes, so sizeof(char) is always and forever 1.
short - Guaranteed to be at least 16 bits. On most systems it really is 16 bits. short, like all other integral data types except for char, is by default signed.
int - Guaranteed to be at least 16 bits, and no shorter than short. On most systems is really is 32 bits (true on basically every x86, x86-64, and IA-64 compiler today).
long - Guaranteed to be at least 32 bits, and no shorter than int. long is generally 32 bits on 32-bit systems and 64-bits on 64-bit systems (on x86-64 and IA-64, this is true).
long long - Not a part of the 2003 C++ Standard, but I use it anyways (it will be a part of the next C++ Standard, and is a part of the 1999 C Standard). Guaranteed to be at least 64 bits. Currently, this holds on most systems.
size_t - This is a typedef from <cstddef> which is guaranteed to be the type that sizeof returns. It is a type suitable for holding the size of an array, and is always unsigned.
Now, isn't that nice and confusing? Boost provides <boost/cstddef.hpp>, which has helpful typedefs from the 1999 C Standard that aren't yet in some C++ compilers. boost::uint8_t is guaranteed to be an unsigned 8 bit type (if the compiler provides one), and similarly for boost::uint64_t, etc.
I have found that in writing portable code, having guaranteed fixed-width datatypes is very important, so that the code will have the same meaning whether compiled on 32-bit or 64-bit systems. Therefore, I typedef the boost/cstddef.hpp types to my own, shorter names:
uc_t, us_t, ul_t, ull_t - unsigned 8, 16, 32, 64 bit types
sc_t, ss_t, sl_t, sll_t - signed 8, 16, 32, 64 bit types
My code isn't 64-bit clean yet, but it's getting there.
I think I'll follow up with a Standard Template Library tutorial later.