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的更多相关文章

  1. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  2. 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP

    [BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...

  3. poj 3254 Corn Fields

    http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  4. Corn Fields——POJ3254状态压缩Dp

    Corn Fields Time Limit: 2000MS Memory Limit: 65536K Description Farmer John has purchased a lush new ...

  5. 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 ...

  6. (转)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 ...

  7. poj3254 Corn Fields (状压DP)

    http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  8. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  9. Many2one类型的fields Compute得到的值 搜索

    v8 默认情况下compute的值不存储于数据库中,在高级搜索中也不可以进行搜索 想要对这种类型的值搜索,需要在field的定义中添加search参数,在search的函数中编写搜索逻辑. 例子: r ...

  10. Resource annotation is not supported on static fields

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paramUtil' d ...

随机推荐

  1. js浮点数运算需要注意的问题

    最近在js运算浮点数时发现了一个问题.问题是这样的:js函数中处理两个浮点数的相加,为了防止出现0.1+0.2=0.30000000000000004的问题,两个数都先乘以10000后再相加,得到结果 ...

  2. java事务的处理

    java的事务处理,如果对数据库进行多次操作,每一次的执行或步骤都是一个事务. 如果数据库操作在某一步没有执行或出现异常而导致事务失败,这样有的事务被执行有的就没有被执行,从而就有了事务的回滚,取消先 ...

  3. core文件分析

    http://baidutech.blog.51cto.com/4114344/904419/ http://www.newsmth.net/pc/pccon.php?id=10001977& ...

  4. 关于nginx upstream的几种配置方式

    平时一直依赖硬件来作load blance,最近研究Nginx来做负载设备,记录下upstream的几种配置方式. 第一种:轮询 upstream test{     server 192.168.0 ...

  5. LoadRunner学习记录--安装遇到的问题一

    安装过程中的出现了此计算机上缺少vc2005_sp1_with_atl_fix_redist 需要到这个目录下lrunner\En\prerequisites\vc2005_sp1_redist\ 手 ...

  6. Selenium2Library系列 keywords 之 _SelectElementKeywords

    # 公有方法 (1)get_list_items(self, locator)  返回labels集合 _get_select_list_options(self, select_list_or_lo ...

  7. html中的div、td 、p 等容器内强制换行和不换行的实现

    div.td .p 等容器内强制换行和不换行,在某些情况下还是比较实用的,下面本文整理了一些相关方面的知识,并有具体的实现方法,需要的朋友可以参考下1.强制不换行,同时以省略号结尾. 代码如下:< ...

  8. [质疑]编程之美求N!的二进制最低位1的位置的问题

    引子:编程之美给出了求N!的二进制最低位1的位置的二种思路,但是呢?但是呢?不信你仔细听我道来. 1.编程之美一书给出的解决思路 问题的目标是N!的二进制表示中最低位1的位置.给定一个整数N,求N!二 ...

  9. win7 提示"Windows 无法连接到System Event Notification Service服务......"的解决办法

    登录win7系统,突然出现如图1的提示,无线网络中断,不能上网,多次插拔无线网卡问题依然. 图1 解决过程如下: 1.检查网卡硬件状况,在设备管理器中查看网卡现象正常,排除网卡硬件故障. 2.查看服务 ...

  10. BITED程序员语言学习心得之:C#语言基础

    一.HelloWorld 我们先来看看最简单的C#代码——HelloWorld: using System; using System.Collections.Generic; using Syste ...