C ++ writes 'or' instead of ||

Possible duplicate:
Alternative C ++ Tokens?

I am working on a task in C ++ with my friend, and we have encoded a lot of his computer / environment (Macbook Pro with Eclipse). In some of the code, he wrote down conditions using and and or rather than && and || . The code compiles on my computer very well, but when I try to compile it on my computer at home (PC with Visual Studio 2010), I get compiler errors and have to switch them. My friend also confirms that this syntax worked using emacs / g ++ on Linux.

I've never seen this before. Is this used widely or supported by most compilers?

+7
source share
5 answers

There are several "alternative representations": and , and_eq , bitand , bitor , compl , not , not_eq , or , or_eq , xor and xor_eq . This is the standard C ++ language feature.

Visual C ++ only supports these keywords if you compile the /Za flag (standard compliance standard).

+9
source
+6
source

They are called operator synonyms , and they appear to be part of the standard, but I'm not sure how widely supported they are.

+3
source

Could you add define to the beginning to get around it?

 #define and && #define or || 
+1
source

This is either caused by a compiler extension, or #define somewhere else in the source code, possibly from iso646.h define ing or to be || and and equal to && . You can also see something like using not instead ! .

If this is an extension for the compiler, and you want you to not have to go through all the or and and tags to || and && , just add a little #define to the top

 #define or || #define and && 
-one
source

All Articles