-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest.c
More file actions
132 lines (125 loc) · 2.99 KB
/
test.c
File metadata and controls
132 lines (125 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "size_asserts.h"
CASSERT_MSVC(sizeof(long) == 4);
CASSERT_GCC(sizeof(long) == sizeof(void*));
struct Integers_Packed
{
// 0
unsigned long long ull;
// 8
long long ll;
// 16
unsigned long ul;
// 24(GCC64); 20(GCC32, MSVC)
long l;
// 32(GCC64); 24(GCC32, MSVC)
unsigned int ui;
// 36(GCC64); 28(GCC32, MSVC)
int i;
// 40(GCC64); 32(GCC32, MSVC)
unsigned short us;
// 42(GCC64); 34(GCC32, MSVC)
short s;
// 44(GCC64); 36(GCC32, MSVC)
unsigned char uc;
// 45(GCC64); 37(GCC32, MSVC)
signed char sc;
// 46(GCC64); 38(GCC32, MSVC)
char c;
// 47(GCC64); 39(GCC32, MSVC)
// Pad 1
// 48(GCC64); 40(GCC32, MSVC)
};
CASSERT_MSVC(sizeof(struct Integers_Packed) == 40);
CASSERT_GCC32(sizeof(struct Integers_Packed) == 40);
CASSERT_GCC64(sizeof(struct Integers_Packed) == 48);
struct Integers_Assorted
{
// 0
char c1;
// Pad 7(GCC64, MSVC); 3(GCC32)
// 8(GCC64, MSVC); 4(GCC32)
long long ll1;
// 16(GCC64, MSVC); 12(GCC32)
char c2;
// 17(GCC64, MSVC); 13(GCC32)
// Pad 7(GCC64); 3(GCC32, MSVC)
// 24(GCC64); 20(MSVC); 16(GCC32)
long l2;
// 32(GCC64); 24(MSVC); 20(GCC32)
char c3;
// 33(GCC64); 25(MSVC); 21(GCC32)
// Pad 3
// 36(GCC64); 28(MSVC); 24(GCC32)
int i3;
// 40(GCC64); 32( MSVC); 28(GCC32)
char c4;
// 41(GCC64); 33(MSVC); 29(GCC32)
// Pad 1
// 42(GCC64); 34(MSVC); 30(GCC32)
short s4;
// 44(GCC64); 36(MSVC); 32(GCC32)
char c5;
// 45(GCC64); 37(MSVC); 33(GCC32)
unsigned char uc5;
// 46(GCC64); 38(MSVC); 34(GCC32)
// Pad 2
// 48(GCC64); 40(MSVC); 36(GCC32)
};
CASSERT_MSVC(sizeof(struct Integers_Assorted) == 40);
CASSERT_GCC32(sizeof(struct Integers_Assorted) == 36);
CASSERT_GCC64(sizeof(struct Integers_Assorted) == 48);
struct Floats_Packed
{
// 0
long double ld;
// 16(GCC64); 12(GCC32); 8(MSVC)
double d;
// Pad 4(GCC32); 0(GCC64, MSVC)
// 24(GCC64); 16(GCC32, MSVC)
float f;
// 28(GCC); 20(GCC32, MSVC)
// Pad 4
// 32(GCC64); 24(GCC32, MSVC)
};
CASSERT_MSVC(sizeof(struct Floats_Packed) == 24);
CASSERT_GCC32(sizeof(struct Floats_Packed) == 24);
CASSERT_GCC64(sizeof(struct Floats_Packed) == 32);
struct Arrays_Packed
{
// 0
char ac[12];
// 12
};
CASSERT(sizeof(struct Arrays_Packed) == 12);
struct Arrays_Mixed
{
// 0
int a;
// 4
// Pad 4(GCC64, MSVC); 0(GCC32)
// 8 (GCC64, MSVC); 4(GCC32)
double b;
// 16 (GCC64, MSVC); 12(GCC32)
int c;
// 20 (GCC64, MSVC); 16(GCC32)
char d[6];
// 26 (GCC64, MSVC); 22(GCC32)
// Pad 6(GCC64, MSVC); 2(GCC32)
// 32 (GCC64, MSVC); 24(GCC32)
};
CASSERT_MSVC(sizeof(struct Arrays_Mixed) == 32);
CASSERT_GCC64(sizeof(struct Arrays_Mixed) == 32);
CASSERT_GCC32(sizeof(struct Arrays_Mixed) == 24);
struct Pointers_Mixed {
// 0
int a;
// 4
// Pad 4(GCC64, MSVC64); 0(GCC32, MSVC32)
// 8 (GCC64, MSVC64); 4(GCC32, MSVC32)
float* p;
// 16 (GCC64, MSVC64); 8(GCC32, MSVC32)
};
CASSERT_MSVC64(sizeof(struct Pointers_Mixed) == 16);
CASSERT_MSVC32(sizeof(struct Pointers_Mixed) == 8);
CASSERT_GCC64(sizeof(struct Pointers_Mixed) == 16);
CASSERT_GCC32(sizeof(struct Pointers_Mixed) == 8);