D
Dennis McCrohan
Hi-
I'm wondering if anyone has any feedback or knowledge of the following
problem. I have searched the MSDN Knowledge Base and not found anything
relevant...
I have an enum similar to:
enum FruitType { apple, pear, peach, mango };
And a class FruitContainer that has a member variable of FruitType,
declared with a bit-width of 2:
FruitType m_myFruit : 2;
and access functions:
FruitType GetMyFruit () { return m_myFruit; }
void SetMyFruit(FruitType myFruit) { m_myFruit = myFruit; }
What we are seeing the Visual C++ 7.1 debugger is that if we call
SetMyFruit() with a value of apple or pear, and then retrieve the value
using GetMyFruit(), everything works as expected. But if we pass
SetMyFruit() the value mango, it ends up getting interpreted as the
integer value -1, and that is what is returned by GetMyFruit(). It
appears that the compiler or run-time is confused and considering the
enum value to be a signed quantity. The same code works correctly on
Solaris (compiled using Workshop) or Linux (using gcc). If I remove the
bit-width from the declaration, the code works correctly on Windows.
Also works if I set the bit-width to 3.
Thanks,
-Dennis McCrohan
Any biases, misguided opinions, or outright idiocy expressed in this
message are absolutely my own, and do not represent those of my
employer...
I'm wondering if anyone has any feedback or knowledge of the following
problem. I have searched the MSDN Knowledge Base and not found anything
relevant...
I have an enum similar to:
enum FruitType { apple, pear, peach, mango };
And a class FruitContainer that has a member variable of FruitType,
declared with a bit-width of 2:
FruitType m_myFruit : 2;
and access functions:
FruitType GetMyFruit () { return m_myFruit; }
void SetMyFruit(FruitType myFruit) { m_myFruit = myFruit; }
What we are seeing the Visual C++ 7.1 debugger is that if we call
SetMyFruit() with a value of apple or pear, and then retrieve the value
using GetMyFruit(), everything works as expected. But if we pass
SetMyFruit() the value mango, it ends up getting interpreted as the
integer value -1, and that is what is returned by GetMyFruit(). It
appears that the compiler or run-time is confused and considering the
enum value to be a signed quantity. The same code works correctly on
Solaris (compiled using Workshop) or Linux (using gcc). If I remove the
bit-width from the declaration, the code works correctly on Windows.
Also works if I set the bit-width to 3.
Thanks,
-Dennis McCrohan
Any biases, misguided opinions, or outright idiocy expressed in this
message are absolutely my own, and do not represent those of my
employer...