这是我的代码..
#include <stdio.h>
struct new {
unsigned short b0 = 0;
unsigned short b1 = 0;
unsigned short b2 = 0;
unsigned short b3 = 0;
unsigned short b4 = 0;
unsigned short b5 = 0;
unsigned short b6 = 0;
unsigned short b7 = 0;
};
int main()
{
printf("Bit Field Example\n");
struct new b; //Seems wrong to me
int result = sizeof(b)/sizeof(*b); //Seems wrong to me
printf("Size: %d\n", result);
return 0;
}
我正在使用 linux 机器来编译上述代码。我知道下面的行是错误的..
int result = sizeof(b)/sizeof(*b);
但我不确定其他任何技术。首先,是否可以计算结构中元素的总数。?请给我一些关于如何做的想法。
提前致谢。