Thread: Interesting: bool != BOOL

  1. #1

    Interesting: bool != BOOL

    Upon compiling some new code i discovered a disturbing error that troubled me for a bit.

    error C2664: 'ResolveCollision' : cannot convert parameter 3 from 'int *' to 'bool *'

    The thing is... parameter 3 is declared specifically as type "BOOL Expire". The function definition asks for "bool * Expire". So i pass "&Expire"... Not a problem right? Wrong. After perusing through the help files at first i find nothing:

    Of course BOOL is a Win32 type but... Isn't a boolean a pretty universal concept? I mean come on...

    Info on Data Types says simply:
    BOOL A Boolean value.

    Not very useful. Then i find this under "bool"

    In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int. In Visual C++ 5.0 and later, bool is implemented as a built-in type with a size of 1 byte. That means that for Visual C++ 4.2, a call of sizeof(bool) yields 4, while in Visual C++ 5.0 and later, the same call yields 1. This can cause memory corruption problems if you have defined structure members of type bool in Visual C++ 4.2 and are mixing object files (OBJ) and/or DLLs built with the 4.2 and 5.0 or later compilers.

    So whats the reasoning behind this?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    well actually, a BOOL (even if bigger) is faster than a bool, that's because a BOOL is 32 bits long and a bool is 8 bits long. Windows is 32 bit, and all of the mov's (assembly) are faster when using 32 bit registers, maybe you're wasting 24 bits (actually it's 31 bits that you're wasting), but it's faster!

    Oskilian

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    I remember looking ages for a completely baffling fault in one of my dialogs. It all seemed to work fine, but the edit boxes behaved very strangely, and had odd colours. One day I noticed that bool != BOOL AND that I had the dialog function declared the other type. Changed that and all problems dissappeared.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Unregistered
    Guest
    BOOL is defined as an int, and TRUE and FALSE are defined as integer constants.

    bool is a keyword and a primitive type added in C++, and true and false are the keywords for the values it may take on.

    Granted, there SHOULD be an automatic BOOL to bool conversion (int to bool, in reality).

  5. #5
    We have a very unique profession. Where else does one have to solve not only the man-made hurdles but also do combat against his own tools?

    It all makes sense when you stop to think about it but as "BOOL" and "bool" behave identically in all other respects one would assume that they could be passed in the same manner.

    >>Granted, there SHOULD be an automatic BOOL to bool conversion (int to bool, in reality).

    Perhaps i should write a solution to that as i (for some odd reason) seem to use both in my code. But more reasonably i should get into some better habits and pick one.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    lightatdawn,

    aim for obscurity and incompatibility,

    define your own boolean as a float(maybe a custom sturct, hehe) or something and only use it!
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing params between managed c++ and unmanaged c++
    By cechen in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2009, 08:46 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. Need Help With an RPG Style Game
    By JayDog in forum Game Programming
    Replies: 6
    Last Post: 03-30-2003, 08:43 PM