#include指令中文件名的有效字符 [英] Valid characters for file name in the #include directive
问题描述
#include
指令中文件名的有效字符是什么?
What are the valid characters for the file name in the #include
directive?
在Linux下,对于例如,除了 /
和 \0
以外,几乎可以使用任何其他字符来获得有效的文件名,但是我会希望C预处理程序对我可以包含的文件名称有更多限制。
Under Linux, for example, I can use pretty much any character except /
and \0
to have a valid file name, but I would expect C preprocessor to be more restrictive about the names of files I can include.
推荐答案
在C ++中,源字符集为在 [lex.charset] 中定义:
In C++, the source character set is defined in [lex.charset]:
基本源字符集由96个字符组成:空格字符,表示水平制表符,垂直制表符,换页和换行的控制字符,以及以下91个字符图形字符:14
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
abcdefghijklmnopqrstu vwxyz
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
ABCDEFGHIJKLMNOPQRSTU VWXYZ
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
0 1 2 3 4 5 6 7 8 9
_ {} []#()< >%:; 。 ? * +-/ ^& | 〜! =,\'
_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '
#include
s的语法为源字符集中的任何字符,但会干扰 #include
解析的字符除外:换行符和>
/ 取决于( [lex.header] ):
And the grammar for #include
s is anything in the source character set except for characters that would mess with the #include
parsing: newlines and >
/"
depending ([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 "
所以这样的事情很完美 † 罚款:
So something like this is perfectly† fine:
#include <hel& lo% world$@-".h>
#include ">.<>."
† 对于完全的定义还是
这篇关于#include指令中文件名的有效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!