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. Operator aliases not known?
Forum Updated to NodeBB v4.3 + New Features

Operator aliases not known?

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 3 Posters 3.4k 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.
  • W Offline
    W Offline
    whpp
    wrote on last edited by
    #1

    Hi,

    I'm relatively new to Qt (three days in), and the first thing I noticed when importing former (vi written, g++ compiled) projects was that any statement using the aliased form of logical operators wouldn't compile:
    @
    if (not false) {
    foo();
    }
    @

    Is this some kind of standard? Can I toggle this behaviour? It's quite annoying to have to sed the whole project before being able to compile it with minGW.

    Any elaboration would be much appreciated.

    W.

    PS. I'm sorry if this issue has been addressed before; I've googled and forum'd for 40 minutes before giving up.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      not is not a valid keyword in C++.

      Probably it was some preprocessor macros that defined things:

      @
      #define not !
      #define or ||
      #define and &&
      // brain to terminal, maybe some quoting is needed
      @

      I would strongly recommend against that approach. Do yourself and your fellow developers a favor and convert to the standard C/C++ operators.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        bq. not is not a valid keyword in C++.

        Actually, I believe it is.

        http://en.cppreference.com/w/cpp/language/operator_alternative

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          whpp: What kind of error messages are you getting when it doesn't compile?

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            mlong: yes, you're right. It's the operator alternatives.

            Some compilers need to have a switch set in order to enable this syntax (e.g. in "RAD Studio XE2":http://docwiki.embarcadero.com/RADStudio/en/Keywords,_Alphabetical_Listing_Index

            According to "wikipedia":http://en.wikipedia.org/wiki/Operators_in_C_and_C++#C.2B.2B_operator_synonyms

            bq. The ANSI C specification makes allowance for these keywords as preprocessor macros in the header file iso646.h. For compatibility with C, C++ provides the header ciso646, inclusion of which has no effect.

            Do you happen to compile in C mode instead of C++?

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • W Offline
              W Offline
              whpp
              wrote on last edited by
              #6

              @mlong:
              'not': undeclared identifier

              The compiler doesn't have a token that he can associate with the word 'not'.

              @volker:
              I'm not a 100% sure, though I dont think so. Compiling in C mode would mean that any C++ code that's not C code cannot be compiled. Following this reasoning, then no, I'm not compiling in C mode.

              Also, I'm running the QtCreator standards, which logically would be auto-set to C++. I can't seem to find a switch that would enable the use of operator alternatives.

              I've tried a few compilers on different systems today, and it seems that all compilers running on Windows machine do not normally support the use of alternative operator names (MinGW, MSVC++). The Intel and GNU compilers on Linux (Fedora 15: G++, Scientific 5: Intel) and Mac (Leopard: G++, Intel) do.

              Including the ISO646.h header file solves the problem, albeit not an elegant solution.

              1 Reply Last reply
              0

              • Login

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