I create some data structures here (with MFC), compiling in MS Visual C ++ 6.0 (yes, it is old).
struct SOpcodeData { BYTE m_byDataType; DWORD m_dwMinValue; DWORD m_dwMaxValue; WORD m_wRepeat; }; const BYTE DATA_U8 = 0; const BYTE DATA_U16 = 1; const BYTE DATA_U32 = 2; SOpcodeData MY_BYTE = { DATA_U8, 0, UCHAR_MAX, 1 }; SOpcodeData MY_WORD = { DATA_U16, 0, USHRT_MAX, 1 }; SOpcodeData MY_DWORD = { DATA_U32, 0, UINT_MAX, 1 };
This code compiles without errors or warnings. But when I try to create an array of my structure type ...
SOpcodeData foo[] = { MY_BYTE, MY_BYTE, MY_WORD, MY_DWORD, MY_BYTE };
VC6 throws a compilation error for each element of the array:
device.cpp (78): error C2440: 'initializing': cannot convert from 'struct SOpcodeData' to 'unsigned char'
There are no user-defined conversion operators available that can perform this conversion, or the statement cannot be called.
Apparently it mistakenly accepts the entire structure type with the first structure field, which is BYTE (or unsigned char for those not used for MFC).
Tried this on Visual Studio 2010 and it works great. But I need to build it using VC6.
I tried explicitly converting to a structure type inside array initialization, but this is redundant and does not solve anything. Any other ideas?