Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. BOOL vs bool

BOOL vs bool

Scheduled Pinned Locked Moved C / C++ / MFC
questionvisual-studio
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Stampor
    wrote on last edited by
    #1

    Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?

    C B F 3 Replies Last reply
    0
    • A Andrew Stampor

      Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      BOOL is a alias (typedef) for an integer. it works nicely with the Windows API, which, as a C API, knows nothing about "bool". it makes nice use of the fact that C (and C++) allow you to write conditionals like this: if (iNumeric) {...} where the condition is true if the test is a non-zero numeric value. "bool" is a native C++ type, not just an integer with a different name. i use "bool" whenever i can, just to keep things clean. with BOOL, there's the chance of accidentally using its integer properties (bVar = 5 * bTrue). -c


      Smaller Animals Software, Inc.

      1 Reply Last reply
      0
      • A Andrew Stampor

        Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?

        B Offline
        B Offline
        Bernhard
        wrote on last edited by
        #3

        as far as i know is bool a keyword from the c++ standard BOOL a data type of win32 i may be wrong.. but i think that is it.. (msdn says that bool should be in msvc++ > 4.2 an own data type and no typedef of an int, like in the old days.. and i gues BOOL is still a typedef of int) hope this helps a little bit bernhard


        "There are three roads to ruin: women, gambling and technicians. The most pleasant is with women, the quickest is with gambling, but the surest is with technicians." Georges Pompidou

        1 Reply Last reply
        0
        • A Andrew Stampor

          Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?

          F Offline
          F Offline
          Fazlul Kabir
          wrote on last edited by
          #4

          (1) bool is C++ specific data type that can have values true or false BOOL is Microsoft specific keyword that is nothing but an integer. As it's defined in "windef.h"

          typedef int BOOL;

          So if you plan to write portable (cross-platform) C++ code, don't use BOOL, use bool instead. (2) size of bool 1 byte, whereas the same for BOOL 4 bytes (which is the size of an 'int') (3) Use 'TRUE' and 'FALSE', while using BOOL and 'true' and 'false' for 'bool'

          BOOL b1 = TRUE;
          bool b2 = true;

          (4) Since BOOL is nothing but an 'int', take extra precaution in using it. Don't simply assume that a BOOL value of other that '1' is always false. My $0.02. // Fazlul


          Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

          T 1 Reply Last reply
          0
          • F Fazlul Kabir

            (1) bool is C++ specific data type that can have values true or false BOOL is Microsoft specific keyword that is nothing but an integer. As it's defined in "windef.h"

            typedef int BOOL;

            So if you plan to write portable (cross-platform) C++ code, don't use BOOL, use bool instead. (2) size of bool 1 byte, whereas the same for BOOL 4 bytes (which is the size of an 'int') (3) Use 'TRUE' and 'FALSE', while using BOOL and 'true' and 'false' for 'bool'

            BOOL b1 = TRUE;
            bool b2 = true;

            (4) Since BOOL is nothing but an 'int', take extra precaution in using it. Don't simply assume that a BOOL value of other that '1' is always false. My $0.02. // Fazlul


            Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

            T Offline
            T Offline
            Tim Smith
            wrote on last edited by
            #5

            Minor little point, sizeof (bool) is implementation specific. The standard even explicitly states it need not be one. I know, I know, I am being anal... Tim Smith Descartes Systems Sciences, Inc.

            F 1 Reply Last reply
            0
            • T Tim Smith

              Minor little point, sizeof (bool) is implementation specific. The standard even explicitly states it need not be one. I know, I know, I am being anal... Tim Smith Descartes Systems Sciences, Inc.

              F Offline
              F Offline
              Fazlul Kabir
              wrote on last edited by
              #6

              I guess I was talking about the implementation on Win32 platform. You are right, other compilers like GCC and some Alpha versions use 4 bytes and even 8 Bytes implementations. Thanks for the comment. // Fazlul


              Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups