【发布时间】:2020-05-17 17:26:46
【问题描述】:
这很挑剔,可能没有任何实际用途。我只是好奇...
从 C++20 工作草案 (n4861) 中,标题名称定义为:
(5.8)
header-name:
< h-char-sequence >
" q-char-sequence "
h-char-sequence :
h-char
h-char-sequence h-char
h-char:
any member of the source character set except new-line and >
q-char-sequence :
q-char
q-char-sequence q-char
q-char:
any member of the source character set except new-line and "
其中“源字符集”定义为:
(5.3.1) The basic source character set consists of 96 characters: the space character, the control characters representing
horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters:9
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " ’
源文件包含定义为:
(15.3.2) A preprocessing directive of the form
# include < h-char-sequence > new-line
...
(15.3.3) A preprocessing directive of the form
# include " q-char-sequence " new-line
...
据我了解,这意味着包含指令#include " <> " 和#include < "" > 都是完全有效的,一个在h-char-sequence 之后,另一个在q-char-sequence 之后。
然而,这对我来说似乎相当奇怪和奇怪。我尝试在 Visual Studio 中创建一个名为 <> 的头文件,该文件(恕我直言)禁止这样做,通知我不能创建这样的头文件,因为字符 < 和 > 都被禁止。
严格来说,Visual Studio 在这方面是遵循标准还是我忽略了什么?两个标头名称是有效还是无效?如果无效,标准的哪一部分禁止这样做?另外,由于源文件包含的定义包含一个空格,#include <iostream> 是否有效?
【问题讨论】:
-
Visual Studio 是否可以创建名称包含 '' 和 '"' 的头文件取决于文件系统和操作系统限制。这与 C++ 标准允许的内容无关.
标签: c++ language-lawyer