X64與X86各個型別的長度
struct T {
char a;
int b;
char c;
};
struct E {
};
// Linux 平臺 (基於 CentOS6.5)
printf("%d\n", sizeof(struct T)); //x86 12 x64 12
printf("%d\n", sizeof(struct E)); //x86 0 x64 0
printf("%d\n", sizeof(char)); //x86 1 x64 1
printf("%d\n", sizeof(short int)); //x86 2 x64 2
printf("%d\n", sizeof(int)); //x86 4 x64 4
printf("%d\n", sizeof(long)); //x86 4 x64 8
printf("%d\n", sizeof(long long)); //x86 8 x64 8
printf("%d\n", sizeof(float)); //x86 4 x64 4
printf("%d\n", sizeof(double)); //x86 8 x64 8
printf("%d\n", sizeof(long double)); //x86 12 x64 16
printf("%d\n", sizeof(void)); //x86 1 x64 1
printf("%d\n", sizeof(void*)); //x86 4 x64 8
printf("%d\n", sizeof(size_t)); //x86 4 x64 8
-------------------------------------------------------------------------------------------------------
// Windows 平臺 (基於 VS2013 Win10)
printf("%d\n", sizeof(struct T)); //x86 12 x64 12
printf("%d\n", sizeof(struct E)); //x86 1 x64 1
printf("%d\n", sizeof(short int)); //x86 2 x64 2
printf("%d\n", sizeof(int)); //x86 4 x64 4
printf("%d\n", sizeof(long)); //x86 4 x64 4
printf("%d\n", sizeof(long long)); //x86 8 x64 8
printf("%d\n", sizeof(float)); //x86 4 x64 4
printf("%d\n", sizeof(double)); //x86 8 x64 8
printf("%d\n", sizeof(long double)); //x86 8 x64 8
//printf("%d\n", sizeof(void)); //error C2070
printf("%d\n", sizeof(void*)); //x86 4 x64 8
printf("%d\n", sizeof(size_t)); //x86 4 x64 8
-------------------------------------------------------------------------------------------------------
型別 Linux x86 Linux x64 WinX86 WinX64
struct T |
12 |
12 |
12 |
12 |
struct E |
0 |
0 |
1 |
1 |
char |
1 |
1 |
1 |
1 |
short int |
2 |
2 |
2 |
2 |
int |
4 |
4 |
4 |
4 |
long |
4 |
8 |
4 |
4 |
long long |
8 |
8 |
8 |
8 |
float |
4 |
4 |
4 |
4 |
double |
8 |
8 |
8 |
8 |
long double |
12 |
16 |
8 |
8 |
void |
1 |
1 |
- |
- |
void* |
4 |
8 |
4 |
8 |
size_t |
4 |
8 |
4 |
8 |
----------------------------------------------------------------------------------------------------------
型別 |
format |
char |
%c |
signed char |
%c (or %hhi for numerical output) |
unsigned char |
%c (or %hhu for numerical output) |
short |
|
unsigned short |
%hu |
int |
|
unsigned |
%u |
long |
|
unsigned long |
%lu |
long long |
|
unsigned long long |
%llu |
float |
%f (promoted automatically to double for printf()) |
double |
%f (%F)(%lf (%lF) for scanf()) |
long double |
%Lf %LF |