Operator aliases not known?
-
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.
-
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.
-
bq. not is not a valid keyword in C++.
Actually, I believe it is.
http://en.cppreference.com/w/cpp/language/operator_alternative
-
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++?
-
@mlong:
'not': undeclared identifierThe 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.