I read in a book that C++ provides additional operators to the usual &,|, and ! which are "and","or" and "not" respectively, plus they come with automatic short circuiting properties where applicable. I would like to use these operators in my code but for some reason the compiler interprets them as identifiers whenever i use them and throws an error. I'm using Visual C++ 2008 Express Edition with SP1. How do i activate these operators to use in my code. Thank you.
The traditional C++ spelling [*] (just like in C) is &&
for "logical", short-circuit and, ||
for "logical", short-circuit or. !
is "logical" not (of course it doesn't short-circuit: what ever would that mean?!-). The bitwise versions are &
, |
, ~
.
According to the C++ standard, the spellings you like (and
, or
, and so on) should also be implemented, but apparently popular compilers disobey that rule. However you should be able to #include <ciso646>
or #include <iso646.h>
to hack around that via macros -- see this page, and if your favorite compiler is missing these header files, just create them the obvious way, i.e.,
#define and &&
#define or ||
and so on. (Kudos and gratitude to the commenters for making me research the issue better and find this out!)
If you want to have the 'and
', 'or
', 'xor
', etc keyword versions of the operators made available in MSVC++ then you either have to use the '/Za
' option to disable extensions or you have to include iso646.h
.