   Typecasting BOOL to bool in C++
  I know that BOOL is the same as int, but I get a warning ('type cast' : conversion from 'BOOL' to 'bool *' of greater size) when trying to typecast a BOOL to a bool value like this:BOOL i = TRUE;bool j = (bool)i;Is there any consequence to this? Is it really necessary to do something like this. It just seems cumbersome.BOOL i = TRUE;bool j;if(i == TRUE)   j = true;else   j = false;
  Well, your sample compile warning seems to indicate that you're casting BOOL to a bool* (that is, pointer to a bool, which is typically 32-bit, while bool is 1 byte). I don't think there's any problem going between BOOL and bool...   ;  The standard does not require bool to be a byte.;Quote:Original post by NickGravelynIs it really necessary to do something like this. It just seems cumbersome.BOOL i = TRUE;bool j;if(i == TRUE)   j = true;else   j = false;What about bool j = (i == TRUE);;  Like someone else said, the problem has nothing to do with casting--you are setting a bool* to a BOOL.  If you fix that, you probably won't even have to cast anything.;  All are relatively common techniques:Turn off the warningOnly use BOOLif (i) j = true; else j = false;j = i ? true : false;j = (i != 0);j = !!i;I prefer the last myself.   ;  I have a question about BOOL. (I think) I've only ever seen it on visual studio. My question is, is it worth anything? It seems to me that it's basically cruft from the days when 'bool' wasn't officially a primitive type in C++, and people would define some enum to make it more obvious that something is a bool... But please correct me if I'm wrong there. I just don't see why anyone would use something that basically exists as a proper language primitive anyway.   ;  It's because the Win32 API (amongst many others) is a C API (not C++).C didn't have the bool type until C99, and the APIs in question were written before that.   ;Quote:Original post by RepliconI have a question about BOOL. (I think) I've only ever seen it on visual studio. My question is, is it worth anything? It seems to me that it's basically cruft from the days when 'bool' wasn't officially a primitive type in C++, and people would define some enum to make it more obvious that something is a bool... But please correct me if I'm wrong there. I just don't see why anyone would use something that basically exists as a proper language primitive anyway.AFAIK BOOL is defined by Win32, one reason for having a typedef (or #define) for bool is that one might want another type to represent a boolean. For instance the following is often true on 32-bit systems:sizeof(bool) == 1;sizeof(int) == 4;32-bit systems is generally better at handling data which is 32 bits, so operations on int can be faster than operations on bool, the problem is that int takes up more memory. Some projects decide they want to use int so they let BOOL be int (or unsigned int, unsigned long or long), TRUE be 1 and FALSE be 0. Some projects might just want the possibility to change the type later on, so they let BOOL be bool, TRUE be true and FALSE be false. Then if they in the future encounter a problem with bool they can change it, for instance sizeof(bool) might be 8 on some 64-bit system, but you can't afford using all that memory so you define BOOL to be unsigned char, TRUE to be 1 and FALSE to be 0, but only on that platform.To the OP: Post the actual code which is giving you this error, as others have said it seems like you try to convert BOOL to a pointer.   ;Quote:Original post by Anon MikeAll are relatively common techniques:Turn off the warningOnly use BOOLif (i) j = true; else j = false;j = i ? true : false;j = (i != 0);j = !!i;I prefer the last myself.j = static_cast<bool>(i);   