#include 指令中文件名的有效字符

Valid characters for file name in the #include directive

#include 指令中文件名的有效字符是什么?

例如,在 Linux 下,我几乎可以使用除 /[=12=] 之外的任何字符来获得有效的文件名,但我希望 C 预处理器更限制我可以包含的文件的名称。

在 C++ 中,源字符集定义在 [lex.charset]:

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:14

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

_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '

#includes 的语法是源字符集中的任何内容,除了会干扰 #include 解析的字符:换行符和 >/"取决于 ([lex.header]):

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 "

所以这样的事情是完美的 很好:

#include <hel& lo% world$@-".h>
#include ">.<>."

关于 "perfectly" 的一些定义...