The Intel® C++ Compiler and the Microsoft Visual C++* compiler differ in way they attribute signedness to bit fields declared with an enum type. Microsoft Visual C++ considers enum bit fields to be signed, even if not all values of the enum type can be represented by the bit field. The Intel C++ Compiler considers an enum bit field to be unsigned, unless the enum type has at least one enum constant with a negative value. The Intel C++ Compiler produces a warning if the bit field is declared with too few bits to represent all the values of the enum type.
This is illustrated using below code.
With Microsoft Visual C++* compiler 2005, 2008, the output is:--
0, 1, 2, 3
0, 1, -2, -1
With Intel® C++ compiler (any version), the output is:--
0, 1, 2, 3
0, 1, 2, 3
So, the bit-fields of an enum type in a class or struct will differ in the signedness rules, as evident from above example code across Microsoft Visual C++* 2005 or 2008 and Intel® C++ Compiler.
This is illustrated using below code.
#include <iostream>
using namespace std;
enum a
{
a1,
a2,
a3,
a4
};
struct S
{
a A1:2;
a A2:2;
a A3:2;
a A4:2;
} s;
int main(int argc, char* argv[])
{
s.A1 = a1;
s.A2 = a2;
s.A3 = a3;
s.A4 = a4;
cout << a1 << ", " << a2 << ", " << a3 << ", " << a4 << endl;
cout << s.A1 << ", " << s.A2 << ", " << s.A3 << ", " << s.A4 << endl;
return 0;
}
With Microsoft Visual C++* compiler 2005, 2008, the output is:--
0, 1, 2, 3
0, 1, -2, -1
With Intel® C++ compiler (any version), the output is:--
0, 1, 2, 3
0, 1, 2, 3
So, the bit-fields of an enum type in a class or struct will differ in the signedness rules, as evident from above example code across Microsoft Visual C++* 2005 or 2008 and Intel® C++ Compiler.
