1. 位字段
struct pid_tag {
unsigned int inactive :1;
unsigned int :1; //1位的填充
unsigned int refcount :6;
unsigned int :0; //填充到下一个字边界
short pid_id;
struct pid_tag *link;
};
位字段的类型必须是 int、unsigned int或signed int(或加上限定符)。
※ 至于int位段的值可不可以取负值则取决于编译器。
2. 用结构赋值的方式给数组赋值
struct s_tag { int a[ 100 ]; };
现在,你可以把数组当做第一等级的类型,用赋值语句拷贝整个数组,以传值的方式把它传递到函数,或者把它作为函数的返回类型。例如:
struct s_tag { int a[100 ]; };
struct S_tag orange, lime, lemon;
struct s_tag twofold( struct s_tag s ) {
int j;
for( j = 0; j < 100; j++ ) s.a[ j ] *= 2;
return s;
}
main() {
int i;
for( i = 0; i < 100; i++ ) lime.a[ i ] = 1;
lemon = two( lime );
orange = lemon; //给整个结构赋值
}
典型情况下,并不会频繁地对整个数组进行赋值操作。但是如果需要这样做,可以通过把它放入结构中来实现。(待续……)