C++ Bit Fields
http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.71%29.aspx
Note
An unnamed bit field of width 0 forces alignment of the next bit field to the next type boundary, where type is the type of the member.
The following example declares a structure that contains bit fields:
// bit_fields1.cpp
struct Date
{
unsigned nWeekDay : ; // 0..7 (3 bits)
unsigned nMonthDay : ; // 0..31 (6 bits)
unsigned nMonth : ; // 0..12 (5 bits)
unsigned nYear : ; // 0..100 (8 bits)
}; int main()
{
}
The conceptual memory layout of an object of type Date is shown in the following figure.
Memory Layout of Date Object

Note that nYear is 8 bits long and would overflow the word boundary of the declared type, unsigned int. Therefore, it is begun at the beginning of a new unsigned int.
It is not necessary that all bit fields fit in one object of the underlying type; new units of storage are allocated, according to the number of bits requested in the declaration.
Microsoft Specific
The ordering of data declared as bit fields is from low to high bit, as shown in the figure above.
END Microsoft Specific
If the declaration of a structure includes an unnamed field of length 0, as shown in the following example,
// bit_fields2.cpp
struct Date
{
unsigned nWeekDay : ; // 0..7 (3 bits)
unsigned nMonthDay : ; // 0..31 (6 bits)
unsigned : 0; // Force alignment to next boundary.
unsigned nMonth : ; // 0..12 (5 bits)
unsigned nYear : ; // 0..100 (8 bits)
}; int main()
{
}
the memory layout is as shown in the following figure.
Layout of Date Object with Zero-Length Bit Field

The underlying type of a bit field must be an integral type, as described in Fundamental Types.
C++ Bit Fields的更多相关文章
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP
[BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...
- poj 3254 Corn Fields
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- Corn Fields——POJ3254状态压缩Dp
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Description Farmer John has purchased a lush new ...
- CLR via C# 3rd - 07 - Constants and Fields
1. Constants A constant is a symbol that has a never-changing value. When defining a constant ...
- (转)Image Segmentation with Tensorflow using CNNs and Conditional Random Fields
Daniil's blog Machine Learning and Computer Vision artisan. About/ Blog/ Image Segmentation with Ten ...
- poj3254 Corn Fields (状压DP)
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- Many2one类型的fields Compute得到的值 搜索
v8 默认情况下compute的值不存储于数据库中,在高级搜索中也不可以进行搜索 想要对这种类型的值搜索,需要在field的定义中添加search参数,在search的函数中编写搜索逻辑. 例子: r ...
- Resource annotation is not supported on static fields
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paramUtil' d ...
随机推荐
- TextView------文字底部或者中间加横线
promotionLinkText = (TextView) this .findViewById(R.id. text_promotion_link ); 中间加横线 promotionLinkTe ...
- Linux基本命令 目录
Linux基本命令 目录 Linux基本命令(1)管理文件和目录的命令 Linux基本命令(2)有关磁盘控件的命令 Linux基本命令(3)文件备份和压缩的命令 Linux基本命令(4)有关关机和查看 ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_value(self, locator, *values)
def unselect_from_list_by_value(self, locator, *values): """Unselects `*values` from ...
- android 性能优化大纲
性能优化系列 分为三个部分:视图篇 逻辑篇 和代码规范篇 . ------2016/9/6 视图篇 主要涵盖视图树层级优化.自定义视图.图片优化,常用布局性能缺陷等多个方面 .把平常经常 ...
- Javascript兼容和CSS兼容总结
javascript部分 1. document.form.item 问题问题:代码中存在 document.formName.item(“itemName”) 这样的语句,不能在FF下运行解决方法: ...
- STL六大组件之——适配器代表大会
适配器也是一种常用的设计模式: 将一个类的接口转换为另一个类的接口,使得原本因接口不兼容而不能合作的两个类可以一起运作.STL提供三种适配器:改变容器接口的容器适配器.改变迭代器接口的迭代器适配器以及 ...
- leetcode:Palindrome Number
Question: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Cou ...
- iOS App中数据加载的6种方式
我们看到的APP,往往有着华丽的启动界面,然后就是漫长的数据加载等待,甚至在无网络的时候,整个处于不可用状态.那么我们怎么处理好界面交互中的加载设计,保证体验无缝衔接,保证用户没有漫长的等待感,而可以 ...
- jsp页面元素和内置对象
java server pages其根本是一个简化的servlet设计.实现了在java当中使用html标签.javaEE标准 一.页面元素 1.静态内容 html.js.css相关标签元素. 2.指 ...
- .NET在IE9中页面间URL传递中文变成乱码的解决办法
在.Net的项目中,鼠标点击查询按钮,转到查询页面,但URL中包含中文时,传到服务器端后,中文变成了乱码(只有IE9出现该问题). 尝试使用Server.UrlEncode()进行编码, ...