枚举中的掩码 [C++]
我现在正在玩位,正在查看 io states 的微软代码,发现了这样的东西:
enum _Iostate
{ // constants for stream states
_Statmask = 0x17};//What is this mask for???
static const _Iostate goodbit = (_Iostate)0x0;
static const _Iostate eofbit = (_Iostate)0x1;
static const _Iostate failbit = (_Iostate)0x2;
static const _Iostate badbit = (_Iostate)0x4;
static const _Iostate _Hardfail = (_Iostate)0x10;
我只是想知道为什么这个掩码是因为代码在没有这个掩码的情况下也可以工作,并且值与没有这个掩码的情况保持不变。 谢谢。
I'm playing at the moment with bits and was looking at microsoft code for io states and discovered something like this:
enum _Iostate
{ // constants for stream states
_Statmask = 0x17};//What is this mask for???
static const _Iostate goodbit = (_Iostate)0x0;
static const _Iostate eofbit = (_Iostate)0x1;
static const _Iostate failbit = (_Iostate)0x2;
static const _Iostate badbit = (_Iostate)0x4;
static const _Iostate _Hardfail = (_Iostate)0x10;
I just wonder why is this mask for because code works without this mask and values stayed the same with as whitout this mask.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它确保
_Iostate
枚举具有正确的大小来保存随后定义的所有位常量及其组合。It makes sure that the
_Iostate
enum has the correct size to hold all the bit constants defined afterward, and their combinations.这是所有可能标志的按位或。您也许可以使用它从整数中的其他位中提取包含标志的部分。
That's a bitwise OR of all possible flags. You could perhaps use it to extract the part containing the flags from other bits in the integer.