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

bool and BOOL

Scheduled Pinned Locked Moved C / C++ / MFC
question
32 Posts 6 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.
  • J Jhony george

    hai, what is the difference between bool and BOOL? reply me..

    Born to win...!

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #4

    if you're coding in C, bool just don't exist (I prefer mention it, even it's obvious). in C++, bool is a native type. it weights 1 byte and takes the values 0_b_0000000**1** (true) or 0_b_0000000**0** (false). you can assign an integer to a bool. if it is different from 0, it equals the value "true", and will be automatically converted into 0_b_0000000**1** anyway. BOOL is different. it is an enum type inherited from the old C days. it's definition is like this :

    enum BOOL {
    FALSE = 0,
    TRUE
    };

    An enum is actually an int, which mean it weights 4 bytes (on a 32 bits system). apparently, Microsoft implements it in a different manner, so you have to be much more careful with it. for instance :

    //if defined like this :
    typedef int BOOL;

    //this can be a mistake :
    BOOL b = 4;
    if (b == true) {
    //never enters here
    // because 4 != 1
    }

    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

    modified on Tuesday, May 20, 2008 9:50 AM

    R CPalliniC N 3 Replies Last reply
    0
    • CPalliniC CPallini

      :-D bool is a C++ keyword, BOOL a Microsoft alias for int:

      typedef int BOOL;

      Any variable declared bool can assume only the following two values: true or false, moreover C++conditional expressions evaluates to a bool result (true or false). On the other hand, a BOOL variable is a fully qualified int and hence can assume any numeric value an int can (MSDN suggest: it should be either TRUE or FALSE). :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #5

      CPallini wrote:

      typedef int BOOL

      not really maybe :cool:

      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      R CPalliniC 2 Replies Last reply
      0
      • T toxcct

        if you're coding in C, bool just don't exist (I prefer mention it, even it's obvious). in C++, bool is a native type. it weights 1 byte and takes the values 0_b_0000000**1** (true) or 0_b_0000000**0** (false). you can assign an integer to a bool. if it is different from 0, it equals the value "true", and will be automatically converted into 0_b_0000000**1** anyway. BOOL is different. it is an enum type inherited from the old C days. it's definition is like this :

        enum BOOL {
        FALSE = 0,
        TRUE
        };

        An enum is actually an int, which mean it weights 4 bytes (on a 32 bits system). apparently, Microsoft implements it in a different manner, so you have to be much more careful with it. for instance :

        //if defined like this :
        typedef int BOOL;

        //this can be a mistake :
        BOOL b = 4;
        if (b == true) {
        //never enters here
        // because 4 != 1
        }

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        modified on Tuesday, May 20, 2008 9:50 AM

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #6

        toxcct wrote:

        BOOL is different. it is an enum type inherited from the old C days. it's definition is like this : enum BOOL { FALSE = 0, TRUE };

        Where did you get this information from? Under Windows, BOOL is defined as an integer in Windef.h

        Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

        T 1 Reply Last reply
        0
        • T toxcct

          CPallini wrote:

          typedef int BOOL

          not really maybe :cool:

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #7

          toxcct wrote:

          not really

          You've gotta be kidding me. CPallini is correct.

          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

          1 Reply Last reply
          0
          • T toxcct

            CPallini wrote:

            typedef int BOOL

            not really maybe :cool:

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #8

            Maybe both my local help and my windef.h file are wrong?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            In testa che avete, signor di Ceprano?

            R 1 Reply Last reply
            0
            • R Rajesh R Subramanian

              toxcct wrote:

              BOOL is different. it is an enum type inherited from the old C days. it's definition is like this : enum BOOL { FALSE = 0, TRUE };

              Where did you get this information from? Under Windows, BOOL is defined as an integer in Windef.h

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #9

              humm, it was in the C days... but anyway, an enum is an int

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              R 1 Reply Last reply
              0
              • T toxcct

                if you're coding in C, bool just don't exist (I prefer mention it, even it's obvious). in C++, bool is a native type. it weights 1 byte and takes the values 0_b_0000000**1** (true) or 0_b_0000000**0** (false). you can assign an integer to a bool. if it is different from 0, it equals the value "true", and will be automatically converted into 0_b_0000000**1** anyway. BOOL is different. it is an enum type inherited from the old C days. it's definition is like this :

                enum BOOL {
                FALSE = 0,
                TRUE
                };

                An enum is actually an int, which mean it weights 4 bytes (on a 32 bits system). apparently, Microsoft implements it in a different manner, so you have to be much more careful with it. for instance :

                //if defined like this :
                typedef int BOOL;

                //this can be a mistake :
                BOOL b = 4;
                if (b == true) {
                //never enters here
                // because 4 != 1
                }

                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                modified on Tuesday, May 20, 2008 9:50 AM

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #10

                toxcct wrote:

                0x00000001 (true) or 0x00000000 (false).

                Uhmmmmmmmmmmm. Never seen a byte having so much hex digits...:-D

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                In testa che avete, signor di Ceprano?

                T J 2 Replies Last reply
                0
                • T toxcct

                  humm, it was in the C days... but anyway, an enum is an int

                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #11

                  I was just asking where was BOOL defined as an enum. Since the C days, BOOL is an int and even the latest Windows SDK, it is so, to have C compatibility. I have never seen BOOL being defined as an enum in the Windows world.

                  Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                  T 1 Reply Last reply
                  0
                  • R Rajesh R Subramanian

                    I was just asking where was BOOL defined as an enum. Since the C days, BOOL is an int and even the latest Windows SDK, it is so, to have C compatibility. I have never seen BOOL being defined as an enum in the Windows world.

                    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #12

                    Rajesh R Subramanian wrote:

                    in the Windows world.

                    man, we are not alone ! ;P

                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      toxcct wrote:

                      0x00000001 (true) or 0x00000000 (false).

                      Uhmmmmmmmmmmm. Never seen a byte having so much hex digits...:-D

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #13

                      what ????? doesn't a Byte having 8 bits ?

                      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                      CPalliniC C 2 Replies Last reply
                      0
                      • CPalliniC CPallini

                        toxcct wrote:

                        0x00000001 (true) or 0x00000000 (false).

                        Uhmmmmmmmmmmm. Never seen a byte having so much hex digits...:-D

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                        J Offline
                        J Offline
                        Jhony george
                        wrote on last edited by
                        #14

                        hai all, about 'bool' i got idea... from all ur replies... but what about BOOL..? i am not clear...

                        Born to win...!

                        modified on Tuesday, May 20, 2008 11:57 PM

                        CPalliniC 1 Reply Last reply
                        0
                        • T toxcct

                          what ????? doesn't a Byte having 8 bits ?

                          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                          CPalliniC Offline
                          CPalliniC Offline
                          CPallini
                          wrote on last edited by
                          #15

                          But it hasn't 8 hexadecimal digits. I.e. I was kidding about your binary numbers prefixed like hexadecimal ones. :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                          In testa che avete, signor di Ceprano?

                          T 1 Reply Last reply
                          0
                          • CPalliniC CPallini

                            But it hasn't 8 hexadecimal digits. I.e. I was kidding about your binary numbers prefixed like hexadecimal ones. :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                            T Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #16

                            you're right, i fixed it.

                            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                            1 Reply Last reply
                            0
                            • CPalliniC CPallini

                              Maybe both my local help and my windef.h file are wrong?

                              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                              R Offline
                              R Offline
                              Rajesh R Subramanian
                              wrote on last edited by
                              #17

                              May be toxcct is on drugs today for a change. :laugh:

                              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                              T CPalliniC 2 Replies Last reply
                              0
                              • R Rajesh R Subramanian

                                May be toxcct is on drugs today for a change. :laugh:

                                Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                                T Offline
                                T Offline
                                toxcct
                                wrote on last edited by
                                #18

                                Rajesh R Subramanian wrote:

                                May be toxcct is on drugs today for a change

                                come on, have you ever worked under linux ? Microsoft IS NOT the standard, even if 85% of the PCs worldwide are windows based... :doh:

                                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                R C 2 Replies Last reply
                                0
                                • T toxcct

                                  what ????? doesn't a Byte having 8 bits ?

                                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                  C Offline
                                  C Offline
                                  Cedric Moonen
                                  wrote on last edited by
                                  #19

                                  toxcct wrote:

                                  doesn't a Byte having 8 bits

                                  Yes, so it is coded 0x00 to 0xFF (hexa representation) or 0b00000000 to 0b11111111 (binary representation).

                                  Cédric Moonen Software developer
                                  Charting control [v1.4]

                                  T 1 Reply Last reply
                                  0
                                  • T toxcct

                                    Rajesh R Subramanian wrote:

                                    May be toxcct is on drugs today for a change

                                    come on, have you ever worked under linux ? Microsoft IS NOT the standard, even if 85% of the PCs worldwide are windows based... :doh:

                                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                    R Offline
                                    R Offline
                                    Rajesh R Subramanian
                                    wrote on last edited by
                                    #20

                                    toxcct wrote:

                                    come on, have you ever worked under linux ?

                                    Yes, why?

                                    toxcct wrote:

                                    Microsoft IS NOT the standard, even if 85% of the PCs worldwide are windows based... [D'Oh!]

                                    So, I don't get the point here. I have worked on development projects on fedora, debian and ubuntu. Linux does not have a BOOL datatype as far as I know. I say - BOOL belongs to Windows. Comments?

                                    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                                    1 Reply Last reply
                                    0
                                    • T toxcct

                                      if you're coding in C, bool just don't exist (I prefer mention it, even it's obvious). in C++, bool is a native type. it weights 1 byte and takes the values 0_b_0000000**1** (true) or 0_b_0000000**0** (false). you can assign an integer to a bool. if it is different from 0, it equals the value "true", and will be automatically converted into 0_b_0000000**1** anyway. BOOL is different. it is an enum type inherited from the old C days. it's definition is like this :

                                      enum BOOL {
                                      FALSE = 0,
                                      TRUE
                                      };

                                      An enum is actually an int, which mean it weights 4 bytes (on a 32 bits system). apparently, Microsoft implements it in a different manner, so you have to be much more careful with it. for instance :

                                      //if defined like this :
                                      typedef int BOOL;

                                      //this can be a mistake :
                                      BOOL b = 4;
                                      if (b == true) {
                                      //never enters here
                                      // because 4 != 1
                                      }

                                      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                      modified on Tuesday, May 20, 2008 9:50 AM

                                      N Offline
                                      N Offline
                                      Nemanja Trifunovic
                                      wrote on last edited by
                                      #21

                                      toxcct wrote:

                                      if you're coding in C, bool just don't exist

                                      It did not exist in C89, but exists in C99[^]

                                      Programming Blog utf8-cpp

                                      1 Reply Last reply
                                      0
                                      • C Cedric Moonen

                                        toxcct wrote:

                                        doesn't a Byte having 8 bits

                                        Yes, so it is coded 0x00 to 0xFF (hexa representation) or 0b00000000 to 0b11111111 (binary representation).

                                        Cédric Moonen Software developer
                                        Charting control [v1.4]

                                        T Offline
                                        T Offline
                                        toxcct
                                        wrote on last edited by
                                        #22

                                        yes yes, fixed already ;)

                                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                        1 Reply Last reply
                                        0
                                        • T toxcct

                                          Rajesh R Subramanian wrote:

                                          May be toxcct is on drugs today for a change

                                          come on, have you ever worked under linux ? Microsoft IS NOT the standard, even if 85% of the PCs worldwide are windows based... :doh:

                                          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                          C Offline
                                          C Offline
                                          Cedric Moonen
                                          wrote on last edited by
                                          #23

                                          toxcct wrote:

                                          have you ever worked under linux

                                          What kind of drug is that ? ;P

                                          Cédric Moonen Software developer
                                          Charting control [v1.4]

                                          T R 2 Replies 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