struct bitfield max size (C99, C++)

后端 未结 4 1282
不知归路
不知归路 2020-12-06 01:47

What is maximal bit width for bit struct field?

struct i { long long i:127;}

Can I define a bit field inside struct, with size of bitfield

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 02:02

    The C++ Standard sets no limits on the size of a bit-field, other than that it must be greater or equal to zero - section 9.6/1. It also says:

    Bit-fields are packed into some addressable allocation unit. [Note: bit-fields straddle allocation units on some machines and not on others. Bit-fields are assigned right-to-left on some machines, left-to-right on others. ]

    Which I suppose could be taken to indicate some sort of maximum size.

    This does not mean that your specific compiler implementation supports arbitrarily sized bit-fields, of course.

提交回复
热议问题