这写程序也写了有几万行了吧,竟然没有认真的考虑过程序的平台可移植性,今天就糗了一个。给大家提个醒。
代码这样写
typedef struct test_a_struct
{
unsigned int a : 1;
}TEST_A_STRUCT;
typedef struct test_b_struct
{
unsigned int b : 1;
}TEST_B_STRUCT;
typedef struct test_c_struct
{
TEST_A_STRUCT var1;
TEST_B_STRUCT var2;
}TEST_C_STRUCT;
sizeof(TEST_C_STRUCT) 是多少?
你能得到答案吗?不同的编译器会给出不同的答案。所以 不要这样写代码,不要怕麻烦,补齐就可以了。
typedef struct test_a_struct
{
unsigned int a : 1;
unsigned int unused :31
}TEST_A_STRUCT;
typedef struct test_b_struct
{
unsigned int b s : 1;
unsigned int unused :31
}TEST_B_STRUCT;