本文介绍了为什么VS不为逻辑运算符定义替代令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

替代标记是 c ++ ,但在Visual Studio 2013中,以下发出编译错误(未声明的标识符):

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?

推荐答案

你问一下理由。这是一个可能的原因,不一定是最影响Visual C ++团队的一个原因:

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


  1. 这些是C中的有效标识符。

  2. Microsoft的建议一直是使用C ++模式用于C和C ++代码,而不是保持现代的C编译器。

  3. 使用这些作为标识符的有效C代码

  4. 尝试写入可移植C ++的人大多使用 / Za 获得最大一致性,其中

  5. 通过包含头文件将它们作为 / Ze 中的关键字进行处理的解决方法非常简单易用。 (G ++的解决方法 -fno-operator-names 也不错,但是将选项放在源代码而不是构建系统中更好一些。)

  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 /Za for maximum conformance anyway, where these are 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.)

这篇关于为什么VS不为逻辑运算符定义替代令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 00:21