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.
  • 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
                          • C Cedric Moonen

                            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 Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #24

                            Cedric Moonen wrote:

                            What kind of drug is that ?

                            i'd better give up there ! lol

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

                            1 Reply Last reply
                            0
                            • J Jhony george

                              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 Offline
                              CPalliniC Offline
                              CPallini
                              wrote on last edited by
                              #25

                              BOOL is fully featured integer, for instance, you can do.

                              // WEIRD BOOL (legal) programming
                              BOOL b;
                              b = 1000;
                              b++;

                              You can't do the same with a bool variable. [added] Well, I made a sanity check, and actually VC++ compiler gives just a warning on the following code

                              bool b;
                              b = 1000; // Warning here (loss of info), at runtime b becomes true.
                              b++; // at runtime b remains true.

                              [/added] As stated by someone (Rajesh ? toxcct?) this is a reminiscence of the C language gold ol days (C has not the bool keyword). Using an int to represent Yes/No pair is simply a matter of convention (and convenience). :)

                              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
                              • C Cedric Moonen

                                toxcct wrote:

                                have you ever worked under linux

                                What kind of drug is that ? ;P

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

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

                                I dunno. Azk CPallini. He'z da one who abuzez drug to answer queris realllly fazzt. He haz gud drugz and gud linkz. azk him plz. :laugh:

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

                                1 Reply 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

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

                                  I supposed too. :laugh:

                                  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?

                                  1 Reply Last reply
                                  0
                                  • CPalliniC CPallini

                                    BOOL is fully featured integer, for instance, you can do.

                                    // WEIRD BOOL (legal) programming
                                    BOOL b;
                                    b = 1000;
                                    b++;

                                    You can't do the same with a bool variable. [added] Well, I made a sanity check, and actually VC++ compiler gives just a warning on the following code

                                    bool b;
                                    b = 1000; // Warning here (loss of info), at runtime b becomes true.
                                    b++; // at runtime b remains true.

                                    [/added] As stated by someone (Rajesh ? toxcct?) this is a reminiscence of the C language gold ol days (C has not the bool keyword). Using an int to represent Yes/No pair is simply a matter of convention (and convenience). :)

                                    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
                                    #28

                                    but one has to be careful with BOOL, as I stated at the end of my most here[^]

                                    CPallini wrote:

                                    C has not the bool keyword

                                    looks like it has[^]

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

                                    CPalliniC 1 Reply Last reply
                                    0
                                    • T toxcct

                                      but one has to be careful with BOOL, as I stated at the end of my most here[^]

                                      CPallini wrote:

                                      C has not the bool keyword

                                      looks like it has[^]

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

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

                                      toxcct wrote:

                                      but one has to be careful with BOOL, as I stated at the end of my most here[^]

                                      Indeed. C language implicit mapping of non-zero values to true and zero value to false is more coherent.

                                      toxcct wrote:

                                      looks like it has[^]

                                      I saw it, but: shhhhhh, noone, except Nemanja, knows. :-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?

                                      R 1 Reply Last reply
                                      0
                                      • CPalliniC CPallini

                                        toxcct wrote:

                                        but one has to be careful with BOOL, as I stated at the end of my most here[^]

                                        Indeed. C language implicit mapping of non-zero values to true and zero value to false is more coherent.

                                        toxcct wrote:

                                        looks like it has[^]

                                        I saw it, but: shhhhhh, noone, except Nemanja, knows. :-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

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

                                        CPallini wrote:

                                        I saw it, but: shhhhhh, noone, except Nemanja, knows.

                                        Oh come on. You are a "C" lover. I would have expected you to know. :-D

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

                                        CPalliniC 1 Reply Last reply
                                        0
                                        • R Rajesh R Subramanian

                                          CPallini wrote:

                                          I saw it, but: shhhhhh, noone, except Nemanja, knows.

                                          Oh come on. You are a "C" lover. I would have expected you to know. :-D

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

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

                                          Well, I'm a traditional-C lover: that fancy new C99 is alien to me. :laugh:

                                          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?

                                          J 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