#include指令中文件名的有效字符 [英] Valid characters for file name in the #include directive

查看:77
本文介绍了#include指令中文件名的有效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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 #includes 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屋!

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