本文主要是介绍在c++中的bit field位域,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
The following properties of bit fields are implementation-defined1、 The value that results from assigning or initializing a bit field with a value out of range, or from incrementing a bit field past its range.
在C++中,如果位域赋值值超过范围,结果由编译器实现。
2、Everything about the actual allocation details of bit fields within the class object
For example, on some platforms, bit fields don't straddle bytes, on others they do
Also, on some platforms, bit fields are packed left-to-right, on others right-to-left
在c++中,位域根据系统大端或者小端的不同,内存布局不同。
3、
Whether char, short, int, long, and long long bit fields that aren't explicitly signed or unsigned are signed or unsigned.
For example, int b:3; may have the range of values 0..7 or -4..3.
在c++中,char short int long long long等没有强制指定是否有符号,那么范围大小由编译器实现。
struct S_CppUint
{
// three-bit unsigned field,
// allowed values are 0...7
unsigned int b : 3;
};
struct S_CppZero
{
// will usually occupy 2 bytes:
// 3 bits: value of b1
// 5 bits: unused
// 6 bits: value of b2
// 2 bits: value of b3
unsigned char b1 : 3;
unsigned char :0; // start a new byte
unsigned char b2 : 6;
unsigned char b3 : 2;
};
这篇关于在c++中的bit field位域的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!