三种方式获得int的size
size_t getIntSize() { int a[2]; return (char*)(a+1) - (char*)a; } size_t getIntSize2() { int n = 0; int i = 1; do { i = i << 8; n++; } while (i != 0); return n; } size_t getIntSize3() { union { short ival; char cval[8]; } v; for (int i = 0; i < 8; ++i) { v.cval[i] = 1; } v.ival = 0; int n = 0; int i = 0; while (!v.cval[i++]) { n++; } return n; }