Why does VS not define the alternative tokens for logical operators?

msvc /za
msvc fpermissive

Alternative tokens are valid c++ keywords, yet in Visual Studio 2013 the following emits a compilation error (undeclared identifier):

int main(int argc, const char* argv[])
{
    int k(1), l(2);
    if (k and l) cout << "both non zero\n";

    return 0;
}

Since and or not have been around for quite some time, is there a reason for not implementing them?

You ask about the rationale. Here's one possible reason, not necessarily the one that most influenced the Visual C++ team:

  1. Those are valid identifiers in C.
  2. Microsoft's recommendation has long been to use C++ mode for both C and C++ code, rather than maintaining a modern C compiler.
  3. Valid C code using these as identifiers would gratuitously break if they were compiled as keywords.
  4. People trying to write portable C++ are mostly using /permissive- or /Za for maximum conformance anyway, which will cause these to be treated as keywords.
  5. The workaround to treat them as keywords in /Ze by including a header file is easy and portable. (G++'s workaround -fno-operator-names isn't bad either, but putting the option in the source code rather than the build system is somewhat nicer.)

Why does VS not define the alternative tokens for logical operators?, Alternative tokens are valid c++ keywords, yet in Visual Studio 2013 the following emits a compilation error (undeclared identifier): The following alternative tokens are part of the core language, and, in all respects of the language, each alternative token behaves exactly the same as its primary token, except for its spelling (the stringification operator can make the spelling visible).

Formally, these keywords are implemented and are supported intrinsically by the compiler without including any headers. However, for that you have to compile your source code in "more standard" mode of that C++ compiler, which means using the /Za option.

By intent, the /Za option is supposed to "disable compiler extensions". Of course, not supporting something that is supposed to be there in a compliant compiler cannot be formally qualified as a "compiler extension". Yet, that just the way things currently are.

Alternative operator representations, Alternative tokens are valid c++ keywords, yet in Visual Studio 2013 the following emits a compilation error (undeclared identifier): int main(int argc, const char*  I have a feeling MSVC incorrectly requires you to #include <ciso646> to use these alternative tokens. – chris Sep 1 '15 at 5:08 Adding #include <ciso646> did the trick, thank you @chris! – ApesInChains Sep 1 '15 at 5:19

VS is nonconforming. This is old news.

To use alternative tokens, include the <ciso646> header. According to the standard, including this header is supposed to have no effect in C++. However, you do need it in VS. So it's safe to just include it always, whenever there is any chance that you might be compiling with VS.

Philosophy of Logic, 2nd Edition, Logical operators: a||b , a&&b , !a There are alternative spellings for several operators and other tokens that use non-ISO646 characters. the C++ version of <iso646.h>, as well as <ciso646>, does not define anything. Alternative tokens. There are alternative spellings for several operators and other tokens that use non-ISO646 characters. In all respects of the language, each alternative token behaves exactly the same as its primary token, except for its spelling (the stringification operator can make the spelling visible).

Because

#include of <iso646.h> (or ciso646) is how we support these keywords

And because "nobody" (before me) ever requested this. Never mind that this was in 2007 and people have been asking for this online since.

Why don't languages use the words "and" and "or" instead of , This means resting with the definition of logical truth that we got to at that point. The theorems (I) and (II) assure us that this definition of logical truth agrees with the alternative definition in terms of models, as long as the object language is not held still to be talking of sets; for, what is a sentence but the set of its tokens? The alternative tokens allow programmers to use C language bitwise and logical operators which could otherwise be hard to type on some international and non-QWERTY keyboards. The name of the header file they are implemented in refers to the ISO/IEC 646 standard, a 7-bit character set with a number of regional variations, some of which have accented characters in place of the punctuation marks used by C operators.

(contemporary update)

I made a small test: A New "Windows Desktop Application" Project. The IDE (Visual Studio 2017 15.7.5) sets, by default, the following C++ language conformance settings: /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline. In addition, I set the C++ Language Standard to ISO C++ /Latest draft (currently up to C++17). In addition, I added, in the main(), the following 2 lines:

bool a, b, c;

a = b and c;

It compiles the text-forms of the logical operators successfully. But when I altered the IDE Conformance mode to No (=> without /permissive-) and re-compile, the compiler marks: "error C2065: 'and': undeclared identifier".

By default, the /permissive- compiler option is set in new projects created by Visual Studio 2017 version 15.5 (December 2017) and later versions. It is not set by default in earlier versions. So if someone created a project prior to version 15.5 and by the time update the IDE to the latest version, still it required to set in the project this compiler option manually.

The /Ze compiler option, which is on by default, enables Microsoft extensions. The /Ze option is deprecated because its behavior is on by default. MSDN recommends to use the /Zc (Conformance) compiler options to control specific language extension features.

C++ Template Metaprogramming: Concepts, Tools, and Techniques from , And for these logical operators, they just doubled the symbol, so && and || supports and , or , bitand , bitor and a couple of other alternative tokens. Python prefers alphabetical operator like and , and does not have a symbol version. Even if the language definition specified your and and or keywords  and and && are functionally the same in C++. The and and or operators are truly valid C++ and part of the language standard.. To elaborate on other answers with a concrete example, there is another reason besides just "readability" to prefer and over &&.

Business Process Management: 14th International Conference, BPM , Concepts, Tools, and Techniques from Boost and Beyond David Abrahams, value equality is called equal_to , and is defined simply: template<class N1, class N2> mpl::bool_<(N1::value == N2::value)> {}; It's important not to confuse equal_to C++ operator for which the language has a textual alternative token name,  The data items on which operators act upon are called operands. Depending on the number of operands that an operator can act upon, operators can be classified as follows: Unary Operators: Those operators that require only single operand to act upon are known as unary operators.For Example increment and decrement operators

Computerworld, In this section, we define the routing of grey and white tokens in exclusive splits, This is not trivial since some activities (this is where data is set) have been skipped by This decision refers to a Boolean variable rejected which is set in the an immediate prioritization of picking their goods; the upper alternative branch is  In logic, a logical connective (also called a logical operator, sentential connective, or sentential operator) is a symbol or word used to connect two or more sentences (of either a formal or a natural language) in a grammatically valid way, such that the value of the compound sentence produced depends only on that of the original sentences and on the meaning of the connective.

C alternative tokens, The 802.3 through 802.5 layers are lower level and define the LAN The 802.3 standard defines Ethernet (CSMA/CD); 802.4 defines Token-Bus and is used that is very important to the PCbased LAN marketplace, although not an 802 In a sense, Netbios can be viewed as a high-level alternative to the 802.1 layer. Each and every small unit in c program is known as tokens. We can also say that tokens are the basic buildings blocks in C language which are constructed together to write a C program.

Comments
  • What is the error message exactly?
  • I'm wondering why is that. It can't be implementation complexity and if they're afraid to break old code the same should apply for gcc et al. A simple grep/replace would resolve any of their codebase conflicts, so is there a deeper reason, is there a dispute behind the scenes or just a feature that nobody cared enough to ask?
  • @NikosAthanasiou A simple grep/replace would probably mess up a lot of comments.
  • GCC is generally much more cavalier about breaking old code in the name of standards conformance than MSVC is.
  • Is there a reference for the /Za part? I cannot try it, and the MSDN page describing the compiler switch does lot list what changes it makes (the relevant link leads to a deleted page).
  • Could you amend the /Za part, please? Apparently it’s very buggy and Microsoft discourages its use (though not in the documentation of course, grrr). See reddit.com/r/cpp/comments/76pmky/til_c_has_and_or_and_not/…
  • Also as a note, /Za causes a bug in MSVC which triggers compiler errors when including windows.h. I made a report about this since I encountered this issue after checking this post: github.com/SasLuca/MSVCBug/blob/master/README.md
  • If you encounter problems with /Za just use /permissive- instead.
  • Doesn't answer the question, which is "why?"
  • @Ben Voigt: Well, it thought the "why" part came from "why not implemented?". Such question is based on an incorrect premise, since they actually are implemented.
  • The "extension" is to let the programmer have these names as identifiers.
  • @Ben Voigt: Yes, but the formal definition of an "extension" clearly says that extensions are not allowed to break any compliant code. In other words, true extensions are allowed to "define what's undefined by the standard", but they are not allowed to "undefine (or redefine) what's already defined by the standard". Formally, extensions are allowed to extend the domain of compilable code, but not allowed to shrink it.
  • As it has been already noted, this "non-conformity" is only specific to the default compilation settings. Most (if not all) compilers are no-conforming in default mode. Specifying the /Za option removes this non-conformity from VS compiler.
  • gcc with C++11 or later without the -pthreads option is another good example.