Reputation: 5821
What are the valid characters for the file name in the #include
directive?
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.
Upvotes: 3
Views: 1894
Reputation: 302817
In C++, the source character set is defined in [lex.charset]:
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
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
_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '
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 ">.<>."
†For some definition of "perfectly" anyway...
Upvotes: 9