Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to use "and", "or" etc. instead of "&&", "||"?

I'm used to the and and or keywords in C++. I've always used them and typing them is fast and comfortable for me. Once I've heard that these aliases are non-standard and may not work on all compilers. But I'm not sure of it, I don't really know if it's true.
Let's assume that I give someone my code, will he have problems compiling it?
Is it all right when I use and, or instead of &&, ||? Or are these keywords really non-standard?
P.S.I use the MinGW compiler.

like image 606
rhino Avatar asked Nov 23 '10 00:11

rhino


People also ask

Is it proper to say and etc?

You should never use “and et cetera.” Remember, et means “and.” “And et cetera” is redundant. Usage note: Don't use a comma after etc.

Is it unprofessional to use etc?

It is perfectly ok to use etc. in an academic paper. Just note, however, that both of them are very sparingly and carefully used in serious writing.

Is it okay to use etc in an essay?

I discourage writers from using etc. in academic writing, because if you are writing an academic paper, you are writing to share information or scholarly research, and you are not conveying any new information with the abbreviation etc.

Can we write and after etc?

Generally, in American English, if "etc." is used in the middle of a sentence, it is followed by a comma. (Tennis, soccer, baseball, etc., are outdoor games.) However, if this word appears at the end of a sentence then the period (which is part of "etc.") serves as the final punctuation mark.


2 Answers

They are in fact standard in C++, as defined by the ISO 14882:2003 C++ standard 2.5/2 (and, indeed, as defined by the 1998 edition of the standard). Note that they are built into the language itself and don't require that you include a header file of some sort.

However, they are very rarely used, and I have yet to see production code that actually uses the alternative tokens. The only reason why the alternative tokens exist in the first place is because these characters on some keyboards (especially non-QWERTY ones) were either nonexistent or clumsy to type. It's still in the standard for backwards compatibility.

Even though they are standard, I highly recommend that you don't use them. The alternative tokens require more characters to type, and the QWERTY keyboard layout already has all the characters needed to type out C++ code without having to use the alternative tokens. Also, they would most likely bewilder readers of your code.

2.5/2 Alternative tokens

In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling. The set of alternative tokens is defined in Table 2.

Table 2 - alternative tokens +--------------+-----------+ | Alternative  |  Primary  | +--------------+-----------+ |    <%        |    {      | |    %>        |    }      | |    <:        |    [      | |    :>        |    ]      | |    %:        |    #      | |    %:%:      |    ##     | |    and       |    &&     | |    bitor     |    |      | |    or        |    ||     | |    xor       |    ^      | |    compl     |    ~      | |    bitand    |    &      | |    and_eq    |    &=     | |    or_eq     |    |=     | |    xor_eq    |    ^=     | |    not       |    !      | |    not_eq    |    !=     | +--------------+-----------+
like image 142
In silico Avatar answered Sep 23 '22 20:09

In silico


These keywords ARE standard and are described in section 2.5 of the standard. Table 2 is a table of these "alternative tokens". You can use them all you want, even though everyone will hate you if you do.

like image 20
Edward Strange Avatar answered Sep 24 '22 20:09

Edward Strange