令我惊讶的是,我刚刚发现MS Visual Studio 2003向上缺少C99 stdint.h.我确定他们有他们的理由,但有谁知道我可以在哪里下载副本?如果没有这个头文件,我就没有uint32_t等有用类型的定义.
我刚刚用bitfields做了一个测试,结果令我感到惊讶.
class test1 {
public:
bool test_a:1;
bool test_b:1;
bool test_c:1;
bool test_d:1;
bool test_e:1;
bool test_f:1;
bool test_g:1;
bool test_h:1;
};
class test2 {
public:
int test_a:1;
int test_b:1;
int test_c:1;
int test_d:1;
int test_e:1;
int test_f:1;
int test_g:1;
int test_h:1;
};
class test3 {
public:
int test_a:1;
bool test_b:1;
int test_c:1;
bool test_d:1;
int test_e:1;
bool test_f:1;
int test_g:1;
bool test_h:1;
};
Run Code Online (Sandbox Code Playgroud)
结果如下: -
sizeof(test1) = 1 // This is what I'd expect. 8 bits in a byte …Run Code Online (Sandbox Code Playgroud)