在一个strut里看到这样一句:unsigned int bDynamic : 1; 请问这个":"是干什么用的?
在一个strut里看到这样一句:
unsigned int bDynamic : 1;
请问这个 ": "是干什么用的? 是不是就是:
unsigned int bDynamic = 1;
如果是的话,为什么不写成等号?
[解决办法]
Bit-fields
When storage space is at a premium, it may be necessary to pack several objects into a single machine word; one common use is a set of single-bit flags in applications like compiler symbol tables. Externally-imposed data formats, such as interfaces to hardware devices, also often require the ability to get at pieces of a word.
struct {
unsigned int is_keyword : 1;
unsigned int is_extern : 1;
unsigned int is_static : 1;
} flags;
This defines a variable table called flags that contains three 1-bit fields. The number following the colon represents the field width in bits. The fields are declared unsigned int to ensure that they are unsigned quantities.
[解决办法]
google位域。另外,楼主需要补C语言基础知识的课。
[解决办法]
二楼转那么长帖,不如干脆告诉他这表示该变量占用1位的空间算了。
[解决办法]
taodm(taodm) ( ) 信誉:100 Blog 2007-1-16 10:15:38 得分: 0
google位域。另外,楼主需要补C语言基础知识的课。
google位域??俺是第一次听说:D
叫google的位域??还是用google去google "位域 "??
[解决办法]
这是结构体问题,可以用指针间接访问成员也可以直接访问...
指针访问时用“-> ”,直接访问时用:结构体名.成员 。
怎么还有“:”访问的吗??????????????????
[解决办法]
2楼说的详细
[解决办法]
位段
[解决办法]
占用1位的空间-同意这个
[解决办法]
普通的char 是c++最小的数据结构了,但是还是按字节来算的.
我们知道1个字节等于8个bit.
c++提供了细微的控制bit的能力.
那就是位域.
unsigned int bDynamic : 1; // 1bit
挺有趣的吧.我的想法是这样就可以为一个字节的某些位命名,然后就可以判断这些位的状态了.
[解决办法]
就是标识该变量占用1位,谭浩强的书里面有讲,还比较详细,可以看看