Serialization
-
Hi all, I have strange error during serialization. I do the following: ar << m_nTime; // (Value typically > 120000) ar << m_bFlag; // (type BOOL) and the m_bFlag always returns as 0; If I do the following: ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp; everything works fine. I'm certainly a little confused and if anyone has some ideas that would be great. Thanks Tom
-
Hi all, I have strange error during serialization. I do the following: ar << m_nTime; // (Value typically > 120000) ar << m_bFlag; // (type BOOL) and the m_bFlag always returns as 0; If I do the following: ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp; everything works fine. I'm certainly a little confused and if anyone has some ideas that would be great. Thanks Tom
_Tom_ wrote:
ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp;
it seems that you are trying to do this...
int tmp;
tmp = m_nTime ? 1 : 0; // depends on the time value you are setting flag
ar << tmp;Im not sure whether i've answered you. if you explain, what you are trying to do will be more useful. SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar." My Blog | Understanding State Pattern in C++ -- modified at 6:59 Wednesday 28th June, 2006 -
Hi all, I have strange error during serialization. I do the following: ar << m_nTime; // (Value typically > 120000) ar << m_bFlag; // (type BOOL) and the m_bFlag always returns as 0; If I do the following: ar << m_nTime; int tmp; tmp = m_bFlag ? 1 : 0; ar << tmp; everything works fine. I'm certainly a little confused and if anyone has some ideas that would be great. Thanks Tom
-
I don't think BOOL is one of the data types supported by CArchive. I usually treat my BOOL types as a flag in a BYTE or DWORD when serializing or something to that effect.
Much scraping for nothing. ;) BOOL is a type defined in WINDEF.H
typedef int BOOL;
and CArchive has an operator
CArchive& operator <<(int i);
Ovidiu Cucu Microsoft MVP - Visual C++
-
Much scraping for nothing. ;) BOOL is a type defined in WINDEF.H
typedef int BOOL;
and CArchive has an operator
CArchive& operator <<(int i);
Ovidiu Cucu Microsoft MVP - Visual C++
Fair enough. I stand corrected. :( I guess because it wasn't in the MSDN list for CArchive, so I just assumed... Anyway, to save face, Serializing a BOOL (int) will take up 4 bytes in the file which can get excessive if there are many BOOL's in many objects. Storing as many of these as flags in BYTE's or DWORD's will prevent waste. Good day and thanks for the correction. :-D
-
Fair enough. I stand corrected. :( I guess because it wasn't in the MSDN list for CArchive, so I just assumed... Anyway, to save face, Serializing a BOOL (int) will take up 4 bytes in the file which can get excessive if there are many BOOL's in many objects. Storing as many of these as flags in BYTE's or DWORD's will prevent waste. Good day and thanks for the correction. :-D
Sincerely, me personal, I wolud like to prefer wasting few bytes than wasting time and adding extra code. :) Although, that's not so big subject to argue... Have a nice day! Ovidiu