位段存值 struct data { int flag:1; int other:31; }; int f() { return 1; } int main() { struct data test; // test.flag=1; test.flag=f(); if(test.flag==1) cout<<"test.flag =1"<<endl;//is right else cout<<"test.flag !=1"<<endl; return 0; } 修改如下 struct data { unsigned int flag:1; int other:31; }; int f() { return 1; } int main() { struct data test; test.flag=f(); if(test.flag==1) cout<<"test.flag =1"<<endl; else cout<<"test.flag !=1"<<endl; return 0; }
位段存值
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
位段那些事
位段(以32位int整数的机器为例) &
C/C++ 位段 -
位段、枚举、联合
位段、枚举、联合
位段 取值 -
C语言位段
有时,存储1个信息不必占用1个字节,只需二进制的1个(或多个)位就够用。如果仍然使用结构类型,则造成内
c语言 开发语言 后端 位段 赋值