1 | struct Empty {}; |
---|---|
2 | class EmptyClass {}; |
3 | class alignas(4) EmptyClassAligned {}; |
4 | class ClassEmptyMember { |
5 | int i[0]; |
6 | }; |
7 | |
8 | struct SingleMember { |
9 | int i; |
10 | }; |
11 | class SingleMemberClass { |
12 | int i; |
13 | }; |
14 | |
15 | struct PaddingMember { |
16 | int i; |
17 | char c; |
18 | }; |
19 | class PaddingMemberClass { |
20 | int i; |
21 | char c; |
22 | }; |
23 | |
24 | const unsigned sizeof_empty = sizeof(Empty); |
25 | const unsigned sizeof_empty_class = sizeof(EmptyClass); |
26 | const unsigned sizeof_empty_class_aligned = sizeof(EmptyClassAligned); |
27 | const unsigned sizeof_class_empty_member = sizeof(ClassEmptyMember); |
28 | const unsigned sizeof_single = sizeof(SingleMember); |
29 | const unsigned sizeof_single_class = sizeof(SingleMemberClass); |
30 | const unsigned sizeof_padding = sizeof(PaddingMember); |
31 | const unsigned sizeof_padding_class = sizeof(PaddingMemberClass); |
32 | |
33 | int main() { |
34 | Empty empty; |
35 | EmptyClass empty_class; |
36 | EmptyClassAligned empty_class_aligned; |
37 | ClassEmptyMember class_empty_member; |
38 | SingleMember single; |
39 | SingleMemberClass single_class; |
40 | PaddingMember padding; |
41 | PaddingMemberClass padding_class; |
42 | // Make sure globals are used. |
43 | return sizeof_empty + sizeof_empty_class + sizeof_class_empty_member + |
44 | sizeof_single + +sizeof_empty_class_aligned + sizeof_single_class + |
45 | sizeof_padding + sizeof_padding_class; |
46 | } |
47 |