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

Valid characters for file name in the #include directive

本文关键字:有效字符 文件名 中文 指令 #include      更新时间:2023-10-16

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

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

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

基本源字符集由 96 个字符组成:空格字符、表示水平制表符、垂直制表符、表单换行符和换行符的控制字符,以及以下 91 个图形字符: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

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

#include s 的语法是源字符集中的任何内容,除了会扰乱#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 ">.<>."
<小时 />

无论如何,对于"完美"的一些定义......