, 1 min read
Operators and, or and xor written in English: is this standard C++?
Kamel was reviewing some code I wrote and through a question he asked, I realized that some code I wrote would not compile under Visual C++. Further investigations showed that the following is valid under GCC, but not under Visual C++:
#include
using std::cout;
using std::endl;
int main(int argv, char ** args)
{
int a = 7;
int b = 3;
cout << (a and b) << endl;
cout << (a or b) << endl;
cout << (a xor b) << endl;
return 0
}
Can anyone help us out? Is this correct code?
Update: It looks like you can get this result under Visual C++ by including “iso646.h”. It includes the following definitions:
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=