Why does VS not define the alternative tokens for logical operators?(为什么 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
";
return 0;
}
既然and or not 已经存在了很长一段时间,是否有理由不实施它们?
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:
- 那些是 C 中的有效标识符.
- 长期以来,Microsoft 一直建议对 C 和 C++ 代码使用 C++ 模式,而不是维护现代 C 编译器.
- 如果将它们编译为关键字,使用这些作为标识符的有效 C 代码将无缘无故地中断.
- 尝试编写可移植 C++ 的人大多使用
/permissive-或/Za以实现最大的一致性,这将导致它们被视为关键字. - 通过包含头文件将它们视为
/Ze中的关键字的解决方法是简单且可移植的.(G++ 的解决方法-fno-operator-names也不错,但是将选项放在源代码中而不是构建系统中会更好一些.)
- Those are valid identifiers in C.
- Microsoft's recommendation has long been to use C++ mode for both C and C++ code, rather than maintaining a modern C compiler.
- Valid C code using these as identifiers would gratuitously break if they were compiled as keywords.
- People trying to write portable C++ are mostly using
/permissive-or/Zafor maximum conformance anyway, which will cause these to be treated as keywords. - The workaround to treat them as keywords in
/Zeby including a header file is easy and portable. (G++'s workaround-fno-operator-namesisn't bad either, but putting the option in the source code rather than the build system is somewhat nicer.)
这篇关于为什么 VS 不为逻辑运算符定义替代标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 VS 不为逻辑运算符定义替代标记?
基础教程推荐
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
