The size of some basic data types is affected by the data model used by your actual compiler. With different compilers the size of your integral types may differ. For a list of data models used by compilers (LP64, ILP64, LP32, ILP32, ...) check out these sites:
http://www.unix.org/version2/whatsnew/lp64_wp.html[
^]
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384083%28v=vs.85%29.aspx[
^]
I usually define my own fixed size data types (int8 - int64 and uint8 - uint64) with the following technique:
#ifdef _MSC_VER
typedef signed __int8 int8;
typedef unsigned __int8 uint8;
typedef signed __int16 int16;
...
#else
#include <stdint.h>
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
...
#endif
Newer Visual C++ versions have an <stdint.h> include like most unix systems. It is a standard header containing int8_t and its friends so its very well portable.
Another tiny detail is that
char
,
signed char
, and
unsigned char
are 3 different types!
char
and
signed char
are not the same as many think but automatic cast is done in 99% of the cases. As a proof you can write 3 overloaded functions accepting these 3 different types!