2007-03 C++ Types Sizes on 32bit/64bit

test_types_sizes.cpp

#include <cstdio>
 
#define ps(x)  printf("%s = %d\n", #x, x);
 
int main(){
        ps( sizeof(char) );
        ps( sizeof(short int) );
        ps( sizeof(int) );
        ps( sizeof(long) );
        ps( sizeof(long long) );
        ps( sizeof(float) );
        ps( sizeof(double) );
        ps( sizeof(long double) );
        ps( sizeof(unsigned char) );
        ps( sizeof(unsigned short int) );
        ps( sizeof(unsigned int) );
        ps( sizeof(unsigned long) );
        ps( sizeof(unsigned long long) );
};

Cmd:
g++ test_types_sizes.cpp ; ./a.out

Result on 32bit:

sizeof(char) = 1
sizeof(short int) = 2
sizeof(int) = 4
sizeof(long) = 4
sizeof(long long) = 8
sizeof(float) = 4
sizeof(double) = 8
sizeof(long double) = 12
sizeof(unsigned char) = 1
sizeof(unsigned short int) = 2
sizeof(unsigned int) = 4
sizeof(unsigned long) = 4
sizeof(unsigned long long) = 8

Result on 64bit:

sizeof(char) = 1
sizeof(short int) = 2
sizeof(int) = 4
sizeof(long) = 8
sizeof(long long) = 8
sizeof(float) = 4
sizeof(double) = 8
sizeof(long double) = 16
sizeof(unsigned char) = 1
sizeof(unsigned short int) = 2
sizeof(unsigned int) = 4
sizeof(unsigned long) = 8
sizeof(unsigned long long) = 8

O ile nie zaznaczono inaczej, treść tej strony objęta jest licencją Creative Commons Attribution-ShareAlike 3.0 License