结构位域最大尺寸(C99,C ++) [英] struct bitfield max size (C99, C++)

查看:444
本文介绍了结构位域最大尺寸(C99,C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是位结构领域最大位宽?

What is maximal bit width for bit struct field?

struct i { long long i:127;}

我可以定义一个位域里面结构,与位域高达128位或256位,或更大尺寸?还有一些超宽载体类型,如SSE2(128位),avx1 / AVX2(256位),AVX-512(512位为下至强公共卫生机构)登记;同时也扩展如 __int128 在海湾合作委员会。

推荐答案

C99§6.7.2.1,第3段:

C99 §6.7.2.1, paragraph 3:

这位前pression指定
  位字段宽度应为
  有整型常量前pression
  该非负值不得
  超过在对象比特数
  即,如果指定的类型
  结肠癌和前pression省略
。如果
  值为零,则声明
  应没有声明。

The expression that specifies the width of a bit-field shall be an integer constant expression that has nonnegative value that shall not exceed the number of bits in an object of the type that is specified if the colon and expression are omitted. If the value is zero, the declaration shall have no declarator.

C ++为0xA§9.6第1款规定:

C++0xa §9.6, paragraph 1:

...恒定-​​EX pression应为
  整型常量前pression用
  值大于或等于零。
  积分常数的值
  前pression可以比大
  在对象比特数
  的再presentation(3.9)
  位字段的类型; 在这种情况下,
  额外位被用作填充比特
  并且不参与价值
  位字段重新presentation(3.9)

... The constant-expression shall be an integral constant expression with a value greater than or equal to zero. The value of the integral constant expression may be larger than the number of bits in the object representation (3.9) of the bit-field’s type; in such cases the extra bits are used as padding bits and do not participate in the value representation (3.9) of the bit-field.

因此​​,在C,可这样做的一切,在C ++中也不会,你希望它是什么做的。

So in C you can't do that at all, and in C++ it won't do what you want it to.

这篇关于结构位域最大尺寸(C99,C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆