c ++是一个空白独立的语言,规则的例外 [英] c++ is a white space independent language, exception to the rule

查看:178
本文介绍了c ++是一个空白独立的语言,规则的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此wikepedia页面将c ++定义为与空白无关的语言。虽然大多数情况下与所有语言一样,规则有例外。我现在唯一能想到的就是这样:

This wikepedia page defines c++ as a "white space independent language". While mostly true as with all languages there are exceptions to the rule. The only one I can think of at the moment is this:

vector<vector<double> >

必须有空格,否则编译器会将>>解释为流运算符。什么其他的。编译一个异常列表很有趣。

Must have a space otherwise the compiler interprets the >> as a stream operator. What other ones are around. It would be interesting to compile a list of the exceptions.

推荐答案

遵循这个逻辑,您可以使用任何两个字符的词法来生成这种规则的例外。例如, + = + = 会有不同的解释。我不会称他们为例外。在C ++中,在许多上下文中,没有空间与一个或多个空间完全不同。当有人说C ++是与空间无关的,它们通常意味着C ++中的一个空格通常与多个空格相同。

Following that logic, you can use any two-character lexeme to produce such "exceptions" to the rule. For example, += and + = would be interpreted differently. I wouldn't call them exceptions though. In C++ in many contexts "no space at all" is quite different from "one or more spaces". When someone says that C++ is space-independent they usually mean that "one space" in C++ is typically the same as "more than one space".

该语言规范规定(参见2.1 / 1),在翻译的第3阶段,允许实现用一个空格字符替换多个空格字符的序列。

This is reflected in the language specification, which states (see 2.1/1) that at phase 3 of translation the implementation is allowed to replace sequences of multiple whitespace characters with one space character.

这篇关于c ++是一个空白独立的语言,规则的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆