The sizes of the built-in C++ types: an experimental investigation

With the transition from the 32-bit x86 architecture to the 64-bit amd-64 and the increasing diffusion of mobile development platforms, the question “what is the size of an int” pops up frequently.

If you want to know what applies to your setup, compile and run the program test_sizeof.cc to find out. The program should detect your architecture / compiler  /operating system combination and print the sizes in bytes of the built-in types void *, short int, int, long int, long long int, float, double, long double, char, wchar_t and bool (caution: the detection is based on compile-time macros, mostly from this collection).

Here are some results for a few combinations.

Architecture Intel x86 AMD64 Intel x86 Intel x86 AMD64 Intel x86
Compiler GNU C/C++ GNU C/C++ GNU C/C++ Microsoft Visual C++ Microsoft Visual C++ GNU C/C++ MinGW32+
Operating system Linux Linux MacOSX Windows Windows Windows
void * 4 8 4 4 8 4
short int 2 2 2 2 2 2
int 4 4 4 4 4 4
long int 4 8 4 4 4 4
long long int 8 8 8 8 8 8
float 4 4 4 4 4 4
double 8 8 8 8 8 8
long double 12 16 16 8 16 12
char 1 1 1 1 1 1
wchar_t 4 4 4 2 2 2
bool 1 1 1 1 1 1

And please send in the output from test_sizeof on your setup !

About paolog

homo technologicus cynicus
This entry was posted in C. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti-Spam Quiz: