What tokens are permitted as arguments to #include?

前端 未结 2 1036
慢半拍i
慢半拍i 2021-01-24 18:21

What sort of tokens are required to be allowed by the standard in includes? E.g., are spaces in file names allowed?

2条回答
  •  时光取名叫无心
    2021-01-24 18:42

    From cppreference on Source file inclusion

    Any preprocessing tokens (macro constants or expressions) are permitted as arguments to #include and __has_include (since C++17) as long as they expand to a sequence of characters surrounded by < > or "".

    Then in Explanation

    Searches for the file in implementation-defined manner. The intent of this syntax is to search for the files that are not controlled by the implementation.

    Furthermore, the c++20 final working draft 5.8 Header names [lex.header] and
    ISO/IEC 9899:1999 6.4.7 Header names except newline, > and ".

    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 "
    

提交回复
热议问题