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 & BOOL

bool & BOOL

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 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.
  • D Offline
    D Offline
    dipuks
    wrote on last edited by
    #1

    Hey Can anyone tell me, whats the difference between if any, of using a bool and a BOOL?

    _ S W 3 Replies Last reply
    0
    • D dipuks

      Hey Can anyone tell me, whats the difference between if any, of using a bool and a BOOL?

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      bool uses 1 byte. It is a data type built into the compiler. BOOL uses 4 bytes. it is a type definition of an int in the file windef.h.

      «_Superman_» I love work. It gives me something to do between weekends.
      Microsoft MVP (Visual C++)

      1 Reply Last reply
      0
      • D dipuks

        Hey Can anyone tell me, whats the difference between if any, of using a bool and a BOOL?

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        BOOL was a workaround used before compilers supported bool (or for use in C, which doesn't support bool). BOOL isn't actually a distinct type but a synonym for int:

        // From "WINDEF.H":
        typedef int BOOL;

        Similarly, the constants TRUE and FALSE are just #defines for the numbers 1 and 0. On the other hand bool is a type.

        Steve

        1 Reply Last reply
        0
        • D dipuks

          Hey Can anyone tell me, whats the difference between if any, of using a bool and a BOOL?

          W Offline
          W Offline
          wangningyu
          wrote on last edited by
          #4

          1、BOOL is Microsoft's macro . In fact, is only 4 bytes of int type. This definitions ,you can find it in the VC setup directory (WINDEF.h、AFX.H), It can be found this following code:

          // WINDEF.H
          typedef unsigned long DWORD;
          typedef int BOOL;
          typedef unsigned char BYTE;
          typedef unsigned short WORD;
          typedef float FLOAT;

          // AFX.H
          #define FALSE 0
          #define TRUE 1
          #define NULL 0

          bool is C/C + + keywords, about MSDN2005 help document, explained below: This keyword is a built-in type. A variable of this type can have values true and false. Conditional expressions have the type bool and so have values of type bool. For example, i!=0 now has true or false depending on the value of i. The values true and false have the following relationship: When a postfix or prefix ++ operator is applied to a variable of type bool, the variable is set to true. The postfix or prefix -- operator cannot be applied to a variable of this type. The bool type participates in integral promotions. An r-value of type bool can be converted to an r-value of type int, with false becoming zero and true becoming one. As a distinct type, bool participates in overload resolution. 2、Define BOOL and bool of the reasons. In the memory space,the true、false、null is occupying 1 bytes.But TRUE、FALSE、NULL is occupying 4 bytes. According to the Intel CPU's paging memory mechanism, 4 bytes can prevent memory inattentive, it can prevent to produce more ram pieces,and help the data transmission. ;P

          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