SigTerm SigTerm - 8 months ago 33
C++ Question

"and"/"or" instead of "&&"/"||" in C++ code - compiler feature or programmer's fault?

Possible Duplicate:

or is not valid C++ : why does this code compile ?


I've recently encountered unusual C++ code written by someone else:

bool operator != (Point p1, Point p2)
return p1.X != p2.X or p1.Y != p2.Y or p1.Z != p2.Z;

as far as I can tell,
isn't declared anywhere, even as macros.
There are also few
s in the code.
As a result, project doesn't build on VC2008 Express. Person that gave me the code said that author has been using mingw compiler.

The question: is this a non-standard compiler feature (I doubt it), is this a part of newer C++ standard (I haven't been watching C++0x), or is this a programmer's problem (say if the guy moved from pascal, he could have been using and/or instead of
because of habit, or because he thinks it is more "readable").


It’s part of the C++ standard. Unfortunately, Visual C++ doesn’t enable that part by default, and Microsoft’s answer to a bug report is “won’t fix, since nobody uses this.”

To fix Visual C++, you need to disable the Microsoft language extensions in the compiler, which can be done with the command line option /Za.

Alternatively, a simple workaround is to include the header <ciso646> which defines these keywords for non-compliant compilers.

(I’m one of the few people who prefer this style, and I’m a bit angry at Microsoft for forcing me to use ASCII soup instead of clean, english words to make my code portable.)