On Sun, May 9, 2010 at 7:02 AM, buginator <[email protected]> wrote: > On 4/30/10, buginator wrote: >> On 4/30/10, Christian Ohm wrote: >> > On Thursday, 29 April 2010 at 22:45, buginator wrote: >> > > After some more tinkering with the code, I finally found the issue >> > > that MSVC was having. In short, a bool in c is a int, and in c++ a >> > > bool !=int. It was always returning 256 on false, and -858993663 on >> > > true. For those that don't see what that is, here: >> > > false = 0x00000100, true = 0xcccccc01 make sense ? >> > >> > >> > No. Is this another Microsoft stupidity? Evalutating true to 1 and false >> to 0 >> > seems to be required by the C++ standard >> >> >> We are not using C++, we are using mixed C & C++, and in the pre C-99 >> standard there is no bool type. It is a typedef to a int for MSVC. >> In C++, the bool type is 1 byte, not a int, in MSVC. >> >> In order to use cross-platform friendly types, then we must not use >> the C++ bool type, and instead use a typedef that will work fine in >> pre C-99 code, hence it should be a int, which is why my patch uses >> BOOL, since we already use that in the codebase, and that is a int on >> all platforms. 'bool' (in the C code) is typedef to a int as well. >> > > A FYI, after reading > http://msdn.microsoft.com/en-us/library/aa505945.aspx it looks like > BOOL is a int, BOOLEAN is a byte. > > We can't do a typedef unsigned char BOOL; (errors out in the C side > won't allow the redefinition). We can't do typedef int bool; (errors > out on the C++ side, won't allow the redefinition), so that leaves us > back to using BOOL instead of bool on the C++ side for *ONLY* > functions that are used in C, and that includes all possible > parameters of that function. > > Will commit the patch sometime Sunday, unless someone else has a > brainstorm to fix this, and no, dropping MSVC isn't part of the > brainstorming. ;)
#ifndef __cplusplus typedef unsigned char bool; // HACK #else // bool is a 1 byte type, which is very likely to be represented as *(unsigned char *)&true == 0x01 and *(unsigned char *)&false == 0x00. #endif //__cplusplus If this can't be done, then maybe #ifndef __cplusplus typedef unsigned char MyBool; // HACK #else typedef bool MyBool; #endif //__cplusplus If bool is declared as an int (and int is usually more than 1 byte) in C, and is a fundamental type (which is usually 1 byte) in C++, then I would expect that looking at a bool returned from C++, in C, would give something like 0xASDFGH00 or 0xASDFGH01, where ASDFGH is whatever happened to be in the high bits of the register. The CCCCCC sounds like a debugging value, though, maybe there's some option to turn it off. _______________________________________________ Warzone-dev mailing list [email protected] https://mail.gna.org/listinfo/warzone-dev
