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
c++questionvisual-studio
15 Posts 8 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 Anonymous

    Does it make sense today to use BOOL rather then bool then? Every compiler has a built in conversion from bool to int (well as long as the API does not expect a pointer to a int).

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #5

    BOOL should be avoided if you're using C++. You should use bool. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

    T 1 Reply Last reply
    0
    • C Christian Graus

      BOOL should be avoided if you're using C++. You should use bool. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

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

      I totally agree. The only place I use BOOL anymore is with my windowing code. If it doesn't have anything to do with windowing, I use a bool. Tim Smith I'm going to patent thought. I have yet to see any prior art.

      A 1 Reply Last reply
      0
      • T Tim Smith

        I totally agree. The only place I use BOOL anymore is with my windowing code. If it doesn't have anything to do with windowing, I use a bool. Tim Smith I'm going to patent thought. I have yet to see any prior art.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #7

        Tim Smith wrote: I totally agree. The only place I use BOOL anymore is with my windowing code. If it doesn't have anything to do with windowing, I use a bool. Couldn't you also use bool in your windowing code? The automatic casting doesn't cost anything remarkable I guess.

        T 1 Reply Last reply
        0
        • N NormDroid

          BOOL is 4 bytes bool is 1 byte BOOL is a typdef'ed int for TRUE/FALSE operations in the Windows API bool is a type safe true/false value in C++ "VB the polished turd of software languages"

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #8

          Norm Almond wrote: bool is 1 byte If IIRC, sizeof(bool) is platform dependent, so you should not make this a general assumption! -- standing so tall, the ground behind no trespassers, on every floor a garden swing, and another door she makes it clear, that everything is hers A place of abode, not far from here, Ms. Van de Veer

          1 Reply Last reply
          0
          • A Anonymous

            Tim Smith wrote: I totally agree. The only place I use BOOL anymore is with my windowing code. If it doesn't have anything to do with windowing, I use a bool. Couldn't you also use bool in your windowing code? The automatic casting doesn't cost anything remarkable I guess.

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

            Yes, but having to add all those != 0 to get rid of that warning is a pain in the butt. I tried using bool 100%, but I found it too annoying with windowing code. Tim Smith I'm going to patent thought. I have yet to see any prior art.

            A A 2 Replies Last reply
            0
            • T Tim Smith

              Yes, but having to add all those != 0 to get rid of that warning is a pain in the butt. I tried using bool 100%, but I found it too annoying with windowing code. Tim Smith I'm going to patent thought. I have yet to see any prior art.

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #10

              Tim Smith wrote: all those != 0 to get rid of that warning could you explain what you mean? this doesn't cause an warning: bool b=true; if(b) { /*do something*/ }

              1 Reply Last reply
              0
              • T Tim Smith

                Yes, but having to add all those != 0 to get rid of that warning is a pain in the butt. I tried using bool 100%, but I found it too annoying with windowing code. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                A Offline
                A Offline
                Anders Molin
                wrote on last edited by
                #11

                You can use !! instead of != ;) bool b = !!SomeFuncReturningBOOL(); No warning, and easier to type than bool b = SomeFuncReturningBOOL() != 0; - Anders Money talks, but all mine ever says is "Goodbye!"

                A 1 Reply Last reply
                0
                • A Anders Molin

                  You can use !! instead of != ;) bool b = !!SomeFuncReturningBOOL(); No warning, and easier to type than bool b = SomeFuncReturningBOOL() != 0; - Anders Money talks, but all mine ever says is "Goodbye!"

                  A Offline
                  A Offline
                  Anonymous
                  wrote on last edited by
                  #12

                  Anders Molin wrote: No warning, and easier to type than bool b = SomeFuncReturningBOOL() != 0; what about bool b = SomeFuncReturningBOOL(); or if there would be a warning (i dont think so) bool b = (bool)SomeFuncReturningBOOL();

                  A 1 Reply Last reply
                  0
                  • A Anonymous

                    Anders Molin wrote: No warning, and easier to type than bool b = SomeFuncReturningBOOL() != 0; what about bool b = SomeFuncReturningBOOL(); or if there would be a warning (i dont think so) bool b = (bool)SomeFuncReturningBOOL();

                    A Offline
                    A Offline
                    Anders Molin
                    wrote on last edited by
                    #13

                    Anonymous wrote: what about bool b = SomeFuncReturningBOOL(); It generates a warning. ;) Anonymous wrote: bool b = (bool)SomeFuncReturningBOOL(); Should work, I guess. :) The !! is still shorter... - Anders Money talks, but all mine ever says is "Goodbye!"

                    A 1 Reply Last reply
                    0
                    • A Anders Molin

                      Anonymous wrote: what about bool b = SomeFuncReturningBOOL(); It generates a warning. ;) Anonymous wrote: bool b = (bool)SomeFuncReturningBOOL(); Should work, I guess. :) The !! is still shorter... - Anders Money talks, but all mine ever says is "Goodbye!"

                      A Offline
                      A Offline
                      Anonymous
                      wrote on last edited by
                      #14

                      Anders Molin wrote: It generates a warning. oh okay! :) thanks, for all feedback. I think I try to kick out BOOL from my code and test with a pure bool coding (if possible). Have a nice weekend.........

                      1 Reply Last reply
                      0
                      • A Anonymous

                        Can someone explain me what's the difference? Sounds like a dump question.... I really don't know it. From previous Windows MFC code I am used to use BOOL, but why is that? C++ does provide a native type bool, shouldn't I use it? Thanks!

                        D Offline
                        D Offline
                        Dimitri Rochette
                        wrote on last edited by
                        #15

                        i dont read every answers but bool is one byte or less. struct DemoSize1 { bool a; } sizeof (DemoSize1) is 1 byte; struct DemoSize2 { bool a; bool b; } sizeof (DemoSize2) is 2 byte; struct DemoSize3 { bool a:1; bool b:1; } sizeof (DemoSize3) is 1 byte; in the last case a and b share the same byte. Dimitri Rochette

                        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