Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ writing 'or' instead of || [duplicate]

Tags:

c++

syntax

Possible Duplicate:
C++ alternative tokens?

I'm working on an assignment in C++ with a friend of mine, and we've been doing lots of the coding on his computer/environment (a Macbook Pro with Eclipse). In some of the code he has written conditions using and and or rather than && and ||. The code compiles just fine on his computer, but when I try and compile it on my computer at home (a PC with Visual Studio 2010) I get compiler errors and am forced to switch them. My friend also attests that this syntax has worked using emacs/g++ in a Linux environment.

I had never seen this type of thing before. Is this used widely or supported by most compilers?

like image 972
Nick Van Hoogenstyn Avatar asked May 15 '11 04:05

Nick Van Hoogenstyn


People also ask

Can we write or instead of || in C++?

There are a handful of "alternative representations": and , and_eq , bitand , bitor , compl , not , not_eq , or , or_eq , xor , and xor_eq . They are a standard language feature of C++. Visual C++ only supports these as keywords if you compile with the /Za (standards conformance mode) flag. Show activity on this post.

What can I use instead of &&?

It's much harder to type bitand instead of and than it is to type & instead of && , and frankly I do think it gains in readability.

What is the difference between || and in C++?

Difference between “||” and “|” It's the same as above, in the case of “||” only one statement is executed and if it returns “true” then the other statement will not be executed. But if the first is false then the other will be checked for the value “true”. The reason for this is the way the “or” operator works.


1 Answers

There are a handful of "alternative representations": and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, and xor_eq. They are a standard language feature of C++.

Visual C++ only supports these as keywords if you compile with the /Za (standards conformance mode) flag.

like image 183
James McNellis Avatar answered Oct 05 '22 08:10

James McNellis