简体   繁体   中英

bitwise operator variations in C++

I read 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 the compiler interprets them as identifiers and throws an error.

I am using Visual C++ 2008 Express Edition with SP1. How do I activate these operators to use in my code?

如果要在MSVC ++中提供运算符的' and ',' or ',' xor '等关键字版本,则必须使用' /Za '选项禁用扩展名,或者必须包含iso646.h

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, ie,

#define and &&
#define or ||

and so on. (Kudos and gratitude to the commenters for making me research the issue better and find this out!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM