关于位段的问题
定义一个位段,使其能用一个int型表示人的某些属性,如性别,血型,肤色,学历等。怎么弄啊,求大神指点
程序代码:
#include "stdio.h" struct person { unsigned int sex : 1; unsigned int blood : 2; unsigned int colour : 4; unsigned int record : 4; }; #define man 0 #define woman 1 #define A 0 #define B 1 #define AB 2 #define O 3 #define yellow 0 #define wite 1 #define black 2 #define brown 3 #define undergraduate 0 #define junior 1 #define master 2 #define doctor 3 int main() { struct person xiaoming; xiaoming.sex = man; xiaoming.blood = AB; xiaoming.colour = yellow; xiaoming.record = undergraduate; }