Maximum size of a bit field in C or C++?

bit-fields, c, c++, struct

Solution

In C11, section 6.7.2.1, clause 4:

The expression that specifies the width of a bit-field shall be an integer constant expression with a nonnegative value that does not exceed the width of an object of the type that would be specified were the colon and expression omitted. If the value is zero, the declaration shall have no declarator.

So in short, it must be between zero and the size of the type if it had not had a bit-field part.

Problem

Possible Duplicate: struct bitfield max size (C99, C++) Is there a limit to the number of bits that I can specify in a bit field in C or C++? For example, could I do this: ``` struct HugeInt { int myInt: 1000; }; ``` I'm asking about both C and C++, since I know that the language specs sometimes differ and wanted to see if the above example was guaranteed to work / not work in C or C++.

Original source

Related problems