'If q-char-sequence is about source file, then why the grammar doesn't have source-file-name? [closed]

C2x, 6.10.2 Source file inclusion, Semantics, 2 (emphasis added):

A preprocessing directive of the form

# include " q-char-sequence " new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters.

C2x, 6.4.7 Header names, Syntax, 1:

header-name:
                 < h-char-sequence >
                 " q-char-sequence "

If q-char-sequence is about source file, then why the grammar doesn't have source-file-name?

Meaning that per grammar "x.c", "x.h", <x.c>, and <x.h> are all header-name. A bit confused.



Solution 1:[1]

The grammar could not have been written

header-name: < source-file-name > | " source-file-name "
source-file-name: h-char-sequence | q-char-sequence

because that would allow either type of char-sequence to be used with either type of delimiter, and that would be incorrect, because the sequences are not the same. h-char-sequence does not allow > and q-char-sequence does not allow ".

If that's not your question then I don't understand what you want to know.

Solution 2:[2]

The grammar only defines h-char-sequence and q-char-sequence as sequence of characters. It is up to the implementation to say which sequences are valid and how they are interpreted. The standards only adds the following constraint:

A #include directive shall identify a header or source file that can be processed by the implementation.

So using a sequence that would not not indentify a correct file should raise a compilation error.

The semantics part adds another requirement ยง5:

The implementation shall provide unique mappings for sequences consisting of one or more nondigits or digits (6.4.2.1) followed by a period (.) and a single nondigit. The first character shall not be a digit. The implementation may ignore distinctions of alphabetical case and restrict the mapping to eight significant characters before the period.

This ensures that the implementation will be able to accept the standard names like stdio.h and that a file having a name like foo.h has to be accepted, provided it maps to an existing file with the correct format.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zwol
Solution 2