#include <bits/stdc++.h>
using namespace std;
struct i2___ {int x,y;}; // 名字太短制表符会崩
struct i1_ll1 {int x;long long y;};
struct i3_ll1 {int x,y,z;long long w;};
struct s3_i1 {short x,y,z;int w;};
struct s1_i1_ll1 {short x;int y; long long z;};
template <typename T>
void test(int expected) {
cout<<"Testsing: "<<typeid(T).name()+1<<",\texpected=\t"<<expected<<",\tsize=\t"<<sizeof(T)<<endl;
}
int main() {
test<i2___>(8);
test<i1_ll1>(12);
test<i3_ll1>(20);
test<s3_i1>(10);
test<s1_i1_ll1>(14);
return 0;
}
Testsing: i2___, expected= 8, size= 8
Testsing: i1_ll1, expected= 12, size= 16
Testsing: i3_ll1, expected= 20, size= 24
Testsing: s3_i1, expected= 10, size= 12
Testsing: s1_i1_ll1, expected= 14, size= 16
结论:结构体有莫名其妙的空间常数。无法解释。