-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmptyStructSizeOf.cpp
More file actions
78 lines (68 loc) · 1.87 KB
/
EmptyStructSizeOf.cpp
File metadata and controls
78 lines (68 loc) · 1.87 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
/**
* \file EmptyStructSizeOf.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
//-------------------------------------------------------------------------------------------------
struct A_1byte
{
};
//-------------------------------------------------------------------------------------------------
struct B_1byte :
A_1byte
{
};
//-------------------------------------------------------------------------------------------------
// error: ISO C++ forbids zero-size array ‘NO_DATA’ [-Werror=pedantic]
#if 0
class C_0byte
{
int NO_DATA[0];
};
#endif
//-------------------------------------------------------------------------------------------------
class D_1byte
{
int foo() { return 0; }
};
//-------------------------------------------------------------------------------------------------
class D_8byte
{
virtual int foo() { return 0; }
};
//-------------------------------------------------------------------------------------------------
class E_4byte
{
int value;
};
//-------------------------------------------------------------------------------------------------
class F_16byte
{
D_8byte value1;
E_4byte value2;
};
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::cout
<< STD_TRACE_VAR(sizeof(A_1byte)) << "\n"
<< STD_TRACE_VAR(sizeof(B_1byte)) << "\n"
// << STD_TRACE_VAR(sizeof(C_0byte)) << "\n"
<< STD_TRACE_VAR(sizeof(D_1byte)) << "\n"
<< STD_TRACE_VAR(sizeof(D_8byte)) << "\n"
<< STD_TRACE_VAR(sizeof(E_4byte)) << "\n"
<< STD_TRACE_VAR(sizeof(F_16byte)) << "\n"
<< std::endl;
return 0;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
sizeof(A_1byte): 1
sizeof(B_1byte): 1
sizeof(C_0byte): 0
sizeof(D_1byte): 1
sizeof(D_8byte): 8
sizeof(E_4byte): 4
sizeof(F_16byte): 16
#endif