位域,volatile限定符
小白vs编程吧
全部回复
仅看楼主
level 6
月无踪 楼主
位域:
当程序需要传递二进制数据给另一个程序或者硬件时可以使用位域。A bit-field must be an integral data type. It can be either signed or unsigned We indicate that a member is a bit-field by following the member name with a colon and a constant expression specifying the number of bits
storage compaction:if possible, packed within adjacent bits of the same integer. Whether and how the bits are packed into the integer is machine-dependent.Bit-fields with more than one bit are usually manipulated using the built-in bitwise
operators.The address-of operator (& ) cannot be applied to a bit-field, so there can be no pointersreferring to class bit-fields. Nor can a bit-field be a static member of its class.
2012年08月29日 13点08分 1
level 6
月无踪 楼主
volatile限定符:
Programs that deal directly with hardware often have data elements whose value is controlledby processes outside the direct control of the program itself. For example, a program mightcontain a variable updated by the system clock. An object should be declared volatile when itsvalue might be changed in ways outside either the control or detection of the compiler. Thevolatile keyword is a directive to the compiler that it should not perform optimizations on suchobjects.
2012年08月29日 13点08分 2
level 6
月无踪 楼主
The volatile qualifier is used in much the same way as is the const qualifier. It is an additionalmodifier to a type:
2012年08月29日 13点08分 3
level 6
月无踪 楼主
In the same way that a class may define const member functions, it can also define memberfunctions as volatile . Only volatile member functions may be called on volatile objects.
2012年08月29日 13点08分 4
level 6
月无踪 楼主
One important difference between the treatment of const and volatile is that the synthesizedcopy and assignment operators cannot be used to initialize or assign from a volatile object.The synthesized copy-control members take parameters that are const references to the classtype. However, a volatile object cannot be passed to a plain or const reference.
2012年08月29日 13点08分 5
level 6
月无踪 楼主
2012年08月29日 13点08分 6
1