BOOL vs bool ?
-
Can someone explain me what's the difference? Sounds like a dump question.... I really don't know it. From previous Windows MFC code I am used to use
BOOL
, but why is that? C++ does provide a native typebool
, shouldn't I use it? Thanks!BOOL is Windows/MFC bool is Standard C++ Max.
-
Can someone explain me what's the difference? Sounds like a dump question.... I really don't know it. From previous Windows MFC code I am used to use
BOOL
, but why is that? C++ does provide a native typebool
, shouldn't I use it? Thanks! -
BOOL is 4 bytes bool is 1 byte BOOL is a typdef'ed int for TRUE/FALSE operations in the Windows API bool is a type safe true/false value in C++ "VB the polished turd of software languages"
-
Does it make sense today to use
BOOL
rather thenbool
then? Every compiler has a built in conversion from bool to int (well as long as the API does not expect a pointer to a int).BOOL should be avoided if you're using C++. You should use bool. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
-
BOOL should be avoided if you're using C++. You should use bool. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
-
I totally agree. The only place I use BOOL anymore is with my windowing code. If it doesn't have anything to do with windowing, I use a bool. Tim Smith I'm going to patent thought. I have yet to see any prior art.
Tim Smith wrote: I totally agree. The only place I use BOOL anymore is with my windowing code. If it doesn't have anything to do with windowing, I use a bool. Couldn't you also use
bool
in your windowing code? The automatic casting doesn't cost anything remarkable I guess. -
BOOL is 4 bytes bool is 1 byte BOOL is a typdef'ed int for TRUE/FALSE operations in the Windows API bool is a type safe true/false value in C++ "VB the polished turd of software languages"
Norm Almond wrote: bool is 1 byte If IIRC, sizeof(bool) is platform dependent, so you should not make this a general assumption! -- standing so tall, the ground behind no trespassers, on every floor a garden swing, and another door she makes it clear, that everything is hers A place of abode, not far from here, Ms. Van de Veer
-
Tim Smith wrote: I totally agree. The only place I use BOOL anymore is with my windowing code. If it doesn't have anything to do with windowing, I use a bool. Couldn't you also use
bool
in your windowing code? The automatic casting doesn't cost anything remarkable I guess. -
Yes, but having to add all those != 0 to get rid of that warning is a pain in the butt. I tried using bool 100%, but I found it too annoying with windowing code. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
Yes, but having to add all those != 0 to get rid of that warning is a pain in the butt. I tried using bool 100%, but I found it too annoying with windowing code. Tim Smith I'm going to patent thought. I have yet to see any prior art.
You can use !! instead of != ;)
bool b = !!SomeFuncReturningBOOL();
No warning, and easier to type thanbool b = SomeFuncReturningBOOL() != 0;
- Anders Money talks, but all mine ever says is "Goodbye!" -
You can use !! instead of != ;)
bool b = !!SomeFuncReturningBOOL();
No warning, and easier to type thanbool b = SomeFuncReturningBOOL() != 0;
- Anders Money talks, but all mine ever says is "Goodbye!" -
Anders Molin wrote: No warning, and easier to type than bool b = SomeFuncReturningBOOL() != 0; what about
bool b = SomeFuncReturningBOOL();
or if there would be a warning (i dont think so)bool b = (bool)SomeFuncReturningBOOL();
Anonymous wrote: what about bool b = SomeFuncReturningBOOL(); It generates a warning. ;) Anonymous wrote: bool b = (bool)SomeFuncReturningBOOL(); Should work, I guess. :) The !! is still shorter... - Anders Money talks, but all mine ever says is "Goodbye!"
-
Anonymous wrote: what about bool b = SomeFuncReturningBOOL(); It generates a warning. ;) Anonymous wrote: bool b = (bool)SomeFuncReturningBOOL(); Should work, I guess. :) The !! is still shorter... - Anders Money talks, but all mine ever says is "Goodbye!"
-
Can someone explain me what's the difference? Sounds like a dump question.... I really don't know it. From previous Windows MFC code I am used to use
BOOL
, but why is that? C++ does provide a native typebool
, shouldn't I use it? Thanks!i dont read every answers but bool is one byte or less. struct DemoSize1 { bool a; } sizeof (DemoSize1) is 1 byte; struct DemoSize2 { bool a; bool b; } sizeof (DemoSize2) is 2 byte; struct DemoSize3 { bool a:1; bool b:1; } sizeof (DemoSize3) is 1 byte; in the last case a and b share the same byte. Dimitri Rochette