Do unnamed bit-fields have well-defined semantics?

血红的双手。 提交于 2019-12-05 02:14:34

Yes, I think an implementation may write arbitrary bits to an unnamed bit field. I think footnote 126 merely states the intention why unnamed bitfields of width larger than 0 were introduced:

An unnamed bit-field structure member is useful for padding to conform to externally imposed layouts.

So basically unnamed bit-fields have the same semantic as padding bits. You just can't rely upon their contents.

Allowing the implementation to basically ignore an unnamed bit-field when writing to an adjacent named bit-field a greatly eases the handling of that field a. The current value of the unnamed field doesn't have to be read and the write can be done atomically in one go. Just as for padding bits that might be contained in the structure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!