这种结构体的声明是什么意思

wwangzhihang100 2009-06-01 05:20:38
#include <stdio.h>
int main()
{
typedef struct yy {
int x:1;
int y:2;
}yy;
yy x;
printf("x.x:%4d,x.y:%4d\n", x.x, x.y);
return 1;
}

里面的:1是干什么用的?
...全文
100 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
fireyou 2009-06-01
  • 打赏
  • 举报
回复
看书不仔细,书上有详细说明的
星空仰望者 2009-06-01
  • 打赏
  • 举报
回复
位数,bit 说白了,就是2进制0或1 的个数
fibbery 2009-06-01
  • 打赏
  • 举报
回复
位域,能够访问到位的。
至善者善之敌 2009-06-01
  • 打赏
  • 举报
回复
这个书上都有吧,你要是没看到那章可以仔细阅读一下。
mengjfu 2009-06-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 coverallwangp 的回复:]
位域
[/Quote]
学习、、、
coverallwangp 2009-06-01
  • 打赏
  • 举报
回复
位域
影子LEON 2009-06-01
  • 打赏
  • 举报
回复
学习了。。。
Dinelgua 2009-06-01
  • 打赏
  • 举报
回复
位域
例子

typedef struct SCSI_MechanStatList_s{
unsigned int CurrentSlot : 5;
unsigned int ChangerState : 2;
unsigned int Fault : 1;
unsigned int Reserved1 : 4;
unsigned int DoorOpen : 1;
unsigned int CDMechanStat : 3;
unsigned int BlockAddress3 : 8;
unsigned int BlockAddress2 : 8;
unsigned int BlockAddress1 : 8;
unsigned int BlockAddress0 : 8;
unsigned int NumOfSlotEnable : 5;
unsigned int Reserved2 : 3;
unsigned int SlotTabLen2 : 8;
unsigned int SlotTabLen1 : 8;
unsigned char SlotTable[32];
} ScsiMechanStatList,*pScsiMechanStatList;
因为这个结构是要发给某个设备的控制数据,实际上就是硬件的控制字
所以必须确保中间无间隔,因此必须用位域来确保发送给设备的指令是严格顺序得
majun01 2009-06-01
  • 打赏
  • 举报
回复
1是结构体中位域的存储声明,表示x只占int型存储空间的一位。
lingyin55 2009-06-01
  • 打赏
  • 举报
回复
位域
T-Quake 2009-06-01
  • 打赏
  • 举报
回复
goodname 2009-06-01
  • 打赏
  • 举报
回复
http://blog.chinaunix.net/u2/63052/showart_1928802.html

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧