'Is the "Type of bit field too small for number of bits" error part of the C++ standard?
The following code generates MSVS Compiler Error C2034 in Visual Studio 2008:
struct TestStruct {
unsigned short var1 : 7;
unsigned short : 9;
bool var2 : 1;
bool : 15; // C2034
};
error C2034: 'TestStruct::<alignment member>': type of bit field too small for number of bits
However, the following code compiles successfully, which seems kind of silly, because I'd think the compiler could have just done this automatically:
struct TestStruct {
unsigned short var1 : 7;
unsigned short : 9;
bool var2 : 1;
bool : 7;
bool : 8;
};
However, both code snippets compile on my Linux GCC compiler. Is one compiler more correct than the other, according to the C++ Standard? If so, which, and why?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
