一个空的C ++文件的效用是什么? [英] What's the utility of an empty C++ file?

查看:107
本文介绍了一个空的C ++文件的效用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

翻译阶段2的第二部分( N3485 )基本上说,如果源文件不以换行符结束,编译器应该对待它,如果它。

The second part of translation phase 2 (section 2.2.2 in N3485) basically says that if a source file does not end in a newline character, the compiler should treat it as if it did.

但是,如果我正确地读取它,则会对空的源文件(它保持为空)产生显式异常。

However, if I'm reading it correctly it makes an explicit exception for empty source files, which remain empty.

确切的文字(加上强调)是:

The exact text (with added emphasis) is:


每个反斜杠字符( \ )后紧跟一个新行字符被删除,拼接物理源行以形成逻辑源行。只有任何物理源行上的最后一个反斜杠才有资格作为这种拼接的一部分。因此,如果产生与通用字符名的语法相匹配的字符序列,则该行为是未定义的。 如果源文件不是空的,并且不以换行符结束,或者以任何拼接发生前的反斜线字符结尾的新行字符,都应被视为处理

Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. If, as a result, a character sequence that matches the syntax of a universal-character-name is produced, the behavior is undefined. A source file that is not empty and that does not end in a new-line character, or that ends in a new-line character immediately preceded by a backslash character before any such splicing takes place, shall be processed as if an additional new-line character were appended to the file.

我无法找出任何情况这将是一个区别,无论源文件是空的还是只包含一个换行符。

I haven't been able to figure out any situations in which it would make a difference whether a source file was empty or consisted of only a newline character.

我希望有人能够阐明这个要求背后的理由。

I'm hoping someone can shed some light on the reasoning behind this requirement.

推荐答案

我认为一个源文件通常由零行或多行组成,每行由一个序列的非新行字符后跟一个新行。任何不符合该要求的源文件都需要特殊处理(因此,您不能从两个不同的源文件中获得由文本组成的行)。

I think the idea is that a source file normally consists of zero or more lines, and each line consists of a sequence of non-new-line characters followed by a new-line. Any source file not meeting that requirement needs special handling (so you don't get lines composed of text from two different source files).

一个空的C ++源文件不是特别是有用,但禁止它没有意义。引用的子句不是区分一个空文件和一个只包含一个新行的文件(它们之间应该没有真正的区别)。

An empty C++ source file is not particularly useful, but there's no point in forbidding it. The quoted clause isn't about distinguishing between an empty file and a file consisting of just one new-line (there should be no real difference between them).

这篇关于一个空的C ++文件的效用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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