Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Boolean in C
Forum Updated to NodeBB v4.3 + New Features

Boolean in C

Scheduled Pinned Locked Moved Unsolved C++ Gurus
34 Posts 11 Posters 7.6k Views 6 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 JonB
    26 Oct 2021, 11:52

    @sierdzio
    If one has to include a header file for them, makes me wonder if they are not "part of the language", just should be available if you include the header. Are they just #defines in that file??

    S Offline
    S Offline
    sierdzio
    Moderators
    wrote on 26 Oct 2021, 11:54 last edited by
    #21

    @JonB said in Boolean in C:

    @sierdzio
    If one has to include a header file for them, makes me wonder if they are not "part of the language", just should be available if you include the header. Are they just #defines in that file??

    yup :D

    #define and    &&
    #define and_eq &=
    #define bitand &
    #define bitor  |
    #define compl  ~
    #define not    !
    #define not_eq !=
    #define or     ||
    #define or_eq  |=
    #define xor    ^
    #define xor_eq ^=
    

    They are not actual C++ language reserved keywords.

    (Z(:^

    J 1 Reply Last reply 26 Oct 2021, 12:10
    1
    • S sierdzio
      26 Oct 2021, 11:54

      @JonB said in Boolean in C:

      @sierdzio
      If one has to include a header file for them, makes me wonder if they are not "part of the language", just should be available if you include the header. Are they just #defines in that file??

      yup :D

      #define and    &&
      #define and_eq &=
      #define bitand &
      #define bitor  |
      #define compl  ~
      #define not    !
      #define not_eq !=
      #define or     ||
      #define or_eq  |=
      #define xor    ^
      #define xor_eq ^=
      

      They are not actual C++ language reserved keywords.

      J Offline
      J Offline
      JonB
      wrote on 26 Oct 2021, 12:10 last edited by
      #22

      @sierdzio
      Hmmmm.... So does gcc have these in some header file, or does their C++ actually have them as reserved? It does have an iso646.h file, with the #defines, yet you said they worked for you in gcc without you explicitly including that? Does it include it automatically or from something else?

      J 1 Reply Last reply 26 Oct 2021, 12:15
      1
      • J JonB
        26 Oct 2021, 12:10

        @sierdzio
        Hmmmm.... So does gcc have these in some header file, or does their C++ actually have them as reserved? It does have an iso646.h file, with the #defines, yet you said they worked for you in gcc without you explicitly including that? Does it include it automatically or from something else?

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 26 Oct 2021, 12:15 last edited by
        #23

        @JonB said in Boolean in C:

        worked for you in gcc without you explicitly including that? Does it include it automatically or from something else

        This header was originally in the C standard library as <iso646.h>.
        Compatibility header, in C defines alternative operator representations which are keywords in C++.
        This means that in a conforming implementation, including this header has no effect.
        

        gcc has mostly a conforming implementation, at least in this regard


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        J 1 Reply Last reply 26 Oct 2021, 12:17
        2
        • J J.Hilk
          26 Oct 2021, 12:15

          @JonB said in Boolean in C:

          worked for you in gcc without you explicitly including that? Does it include it automatically or from something else

          This header was originally in the C standard library as <iso646.h>.
          Compatibility header, in C defines alternative operator representations which are keywords in C++.
          This means that in a conforming implementation, including this header has no effect.
          

          gcc has mostly a conforming implementation, at least in this regard

          J Offline
          J Offline
          JonB
          wrote on 26 Oct 2021, 12:17 last edited by
          #24

          @J-Hilk said in Boolean in C:

          This header was originally in the C standard library as <iso646.h>.

          So what file is this in, which you say is included automatically?

          J J 2 Replies Last reply 26 Oct 2021, 12:19
          0
          • J JonB
            26 Oct 2021, 12:17

            @J-Hilk said in Boolean in C:

            This header was originally in the C standard library as <iso646.h>.

            So what file is this in, which you say is included automatically?

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 26 Oct 2021, 12:19 last edited by
            #25

            @JonB said in Boolean in C:

            which you say is included automatically?

            My understanding is that it is NOT included automatically in conforming C++ implementations because those understand these words as keywords and don't need this header file (which is only there for compatibility reasons).

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply 26 Oct 2021, 12:22
            2
            • J JonB
              26 Oct 2021, 12:17

              @J-Hilk said in Boolean in C:

              This header was originally in the C standard library as <iso646.h>.

              So what file is this in, which you say is included automatically?

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 26 Oct 2021, 12:22 last edited by
              #26

              @JonB I'm talking about the iso646.h @sierdzio mentioned

              https://en.cppreference.com/w/cpp/header/ciso646

              Probably the reason why MSVC doesn't have those as keywords but requires this header is, IIRC, that it doesn't have/use a dedicated c compiler for c headers and it would break legacy stuff if those were used as keywords


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • J jsulm
                26 Oct 2021, 12:19

                @JonB said in Boolean in C:

                which you say is included automatically?

                My understanding is that it is NOT included automatically in conforming C++ implementations because those understand these words as keywords and don't need this header file (which is only there for compatibility reasons).

                J Offline
                J Offline
                JonB
                wrote on 26 Oct 2021, 12:22 last edited by
                #27

                @jsulm
                Mine too. But I quote from @sierdzio above:

                Last time I tried was last year. Clang, GCC all are 100% fine with it, MSVC was throwing errors.

                I now see it's supposed to be defined in some iso646.h header, I never included it, perhaps that's the reason.

                My question is (should be) aimed at him: he says it worked automatically in GCC/Clang (but not MSVC) with no #include from him, that's what I'm trying to understand.

                1 Reply Last reply
                0
                • fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on 26 Oct 2021, 21:22 last edited by
                  #28

                  I know Boolean is someone's name.
                  But it kind of look like a diet fad to scare people skinny: boo-lean.

                  C++ is a perfectly valid school of magic.

                  J 1 Reply Last reply 27 Oct 2021, 05:10
                  0
                  • fcarneyF fcarney
                    26 Oct 2021, 21:22

                    I know Boolean is someone's name.
                    But it kind of look like a diet fad to scare people skinny: boo-lean.

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 27 Oct 2021, 05:10 last edited by
                    #29

                    @fcarney You mean Anne Boleyn, one of the wifes of king Henry VI which was executed. She was mother of Elisabeth I :-)

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    jeremy_kJ 1 Reply Last reply 27 Oct 2021, 05:27
                    0
                    • J jsulm
                      27 Oct 2021, 05:10

                      @fcarney You mean Anne Boleyn, one of the wifes of king Henry VI which was executed. She was mother of Elisabeth I :-)

                      jeremy_kJ Offline
                      jeremy_kJ Offline
                      jeremy_k
                      wrote on 27 Oct 2021, 05:27 last edited by
                      #30

                      @jsulm said in Boolean in C:

                      @fcarney You mean Anne Boleyn, one of the wifes of king Henry VI which was executed. She was mother of Elisabeth I :-)

                      Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.

                      Presumably @fcarney is referring to George Boole.

                      Asking a question about code? http://eel.is/iso-c++/testcase/

                      Kent-DorfmanK 1 Reply Last reply 27 Oct 2021, 18:19
                      1
                      • J J.Hilk
                        26 Oct 2021, 11:37

                        @sierdzio , @JonB

                        are you guys aware, that not is a valid keyword in c++ ?

                        https://en.cppreference.com/w/cpp/keyword/not

                        Kent-DorfmanK Offline
                        Kent-DorfmanK Offline
                        Kent-Dorfman
                        wrote on 27 Oct 2021, 18:15 last edited by
                        #31

                        @J-Hilk said in Boolean in C:

                        are you guys aware, that not is a valid keyword in c++ ?

                        Heretic!
                        and the discussion is about C. ;^P

                        But to the point about superfluous comparisons: I guess is comes down to whether you understand the grammar. If you understand that all comparison operations evaluate to a boolean value (zero, or not zero) then it should become evident that explicit comparisons of booleans to a constant is redundant.

                        1 Reply Last reply
                        0
                        • jeremy_kJ jeremy_k
                          27 Oct 2021, 05:27

                          @jsulm said in Boolean in C:

                          @fcarney You mean Anne Boleyn, one of the wifes of king Henry VI which was executed. She was mother of Elisabeth I :-)

                          Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.

                          Presumably @fcarney is referring to George Boole.

                          Kent-DorfmanK Offline
                          Kent-DorfmanK Offline
                          Kent-Dorfman
                          wrote on 27 Oct 2021, 18:19 last edited by
                          #32

                          @jeremy_k said in Boolean in C:

                          Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.

                          I guess technically I AM, being a decendent of Mary Boleyn...as for being dangerous... :^D

                          J 1 Reply Last reply 27 Oct 2021, 18:33
                          0
                          • Kent-DorfmanK Kent-Dorfman
                            27 Oct 2021, 18:19

                            @jeremy_k said in Boolean in C:

                            Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.

                            I guess technically I AM, being a decendent of Mary Boleyn...as for being dangerous... :^D

                            J Offline
                            J Offline
                            JonB
                            wrote on 27 Oct 2021, 18:33 last edited by
                            #33

                            @Kent-Dorfman said in Boolean in C:

                            I guess technically I AM, being a decendent of Mary Boleyn

                            Are you also claiming to be a descendant of Henry VIII? :)

                            Kent-DorfmanK 1 Reply Last reply 27 Oct 2021, 19:15
                            0
                            • J JonB
                              27 Oct 2021, 18:33

                              @Kent-Dorfman said in Boolean in C:

                              I guess technically I AM, being a decendent of Mary Boleyn

                              Are you also claiming to be a descendant of Henry VIII? :)

                              Kent-DorfmanK Offline
                              Kent-DorfmanK Offline
                              Kent-Dorfman
                              wrote on 27 Oct 2021, 19:15 last edited by
                              #34

                              @JonB said in Boolean in C:

                              Are you also claiming to be a descendant of Henry VIII? :)

                              Claiming is such a strict definition. It is an interesting possibility that historians play with, and I cannot discount how much my cousins look like Henry in his later years (according to paintings)...and we do know that grammy Mary was quite the party girl.

                              1 Reply Last reply
                              1

                              21/34

                              26 Oct 2021, 11:54

                              • Login

                              • Login or register to search.
                              21 out of 34
                              • First post
                                21/34
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved