【问题标题】:Valid characters for file name in the #include directive#include 指令中文件名的有效字符
【发布时间】:2016-03-14 01:03:20
【问题描述】:

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

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

【问题讨论】:

    标签: c++ c c-preprocessor


    【解决方案1】:

    在 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

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

    #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 ">.<>."
    

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

    【讨论】:

      猜你喜欢
      • 2015-11-07
      • 2012-02-24
      • 2021-10-14
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      相关资源
      最近更新 更多