Thread: Bool

  1. #1
    Registered User
    Join Date
    Mar 2009

    Question Bool

    Hi all

    A book I'm learning Direct3D from is causing more problems than it's solving so far!

    I am coming across a data type called "BOOL" - in capitals, not to be confused with the standard "bool" syntax. The only data that it seems to be given is "TRUE" AND "FALSE" - again with capitals.

    The book does not provide any header that might contain a BOOL class, and seems to expect the reader not to be surprised by this new data type. It seems to treat the data as an array as it checks the data using the following syntax:

    if (buf[1]=='F')
    It's obviously checking the letter in the "TRUE" or "FALSE" data provided by the user (although it's not clear why it's checking buf[1] instead of buf[0] ).

    I was not surprised when Visual Express 2008 came back with: "syntax error: identifier 'BOOL'. However I can't change this data to a standard "bool" data type without majorly screwing with other code (it's a big program and I don't really have to space to explain why this this is!).

    I was wondering if anyone has come across this before? If so please could you explain where "BOOL" comes from and how it works? Bonus points if you can also explain why the above if statement would check buf[1] instead of buf[0]!

    Thanks a lot :-)

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    BOOL is a "Windows" data type for a boolean, since C90 does not actually define a boolean type, and Windows API is built for C90.
    BOOL is merely a typedef for int. Likewise, TRUE and FALSE is 1 and 0 respectively.
    If you include windows.h, you'll likely get this typedef for free. Otherwise you can create them manually or change to bool/true/false.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Thanks for that, I thought Windows API was already being included but I'll check when I get a second. :-)

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. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. DirectInput help
    By Muphin in forum Game Programming
    Replies: 2
    Last Post: 09-10-2005, 11:52 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