struct node
{
unsigned int a:4; //位段a,占4位
unsigned int :0; //无名位段,占0位
unsigned int b:4; //位段b,占4位
int c:32; //位段c,占32位
int :6; //无名位段,占6位
};
/*测试位段 201110.12*/
#include<iostream>
using namespace std;
typedef struct node
{
unsigned int a:1; //存在一个非0位的位段,则至少占4Byte
}S;
typedef struct node1 //在C++中占1字节的空间 ,在C中占0字节
{
unsigned int :0;
}S1;
typedef struct node2
{
unsigned int a:1;
unsigned int :0; //下一个位段放在一个新的位段存储单元 ,所以占4+4=8Byte
unsigned c:32;
}S2;
typedef struct node3
{
unsigned int a:4;
unsigned int :0;
int :6; //这个位段放在一个新的位段存储单元
unsigned c:32; //由于6+32>32,所位段c也放在一个新的位段存储单元,所以占4+4+4=12Byte
}S3;
typedef struct node4
{
unsigned int a:1;
char b; //在一个位段存储单元中能够存下所有的成员,所以占4Byte
int c:1;
int d:2;
unsigned int e:2;
}S4;
int main(int argc, char *argv[])
{
S4 s4;
s4.a=1;
s4.c=1;
s4.d=2;
s4.e=3;
printf("%d %d %d %d\n",s4.a,s4.c,s4.d,s4.e);
printf("%d %d %d %d %d\n",sizeof(S),sizeof(S1),sizeof(S2),sizeof(S3),sizeof(S4));
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有