C preprocessor: what is the rationale behind not allowing argument of the #include directive to begin with a digit?

Viewed 82

N2479 C17..C2x working draft — February 5, 2020 ISO/IEC 9899:202x (E):

6.10.2 Source file inclusion

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.

Question: what is the rationale behind not allowing argument (char-sequence) of the #include directive to begin with a digit?

Extra question: compilers seem to not generate any diagnostic message when the shall requirement above is violated (ex. use of #include "1.h"). Why?

UPD. Later my colleague answered: the The first character shall not be a digit is related only to unique mappings. So, the standard was misinterpreted.

1 Answers

Question: what is the rationale behind not allowing argument (char-sequence) of the #include directive to begin with a digit?

By itself, the sentence “The first character shall not be a digit” would seem to be saying that a C program shall not use a digit as the first character in a header name. However, it is between two sentences that tell us how C implementations must process header names and is in a clause, 6.10, that tells us how implementations process #include directives. The clause that tells us the grammar for header names is in a different place in the C standard, 6.4.7, where it gives #include <1/a.h> as an example of a possible directive (C 2018 6.4.7 4).

So I believe the intent of 6.10.2 5 is to provide a quality-of-implementation guarantee, saying that you cannot implement C directly using a file system that does not support at least eight characters in the base part of file names, but you can use a file system that ignores case (per its last sentence) or that does not support names beginning with a digit. Although “The first character shall not be a digit” appears to be a prohibition on C programs, that is because a mistake was made in putting this in a separate sentence without qualification; the first two sentences should have been something like “The implementation shall provide unique mappings for sequences consisting of a nondigit (6.4.2.1) followed by zero or more nondigits or digits followed by a period (.) and a single nondigit.”

(In C 1990, this paragraph appears in 6.8.2, where the significance requirement is only for six characters. It was increased to eight in C 1999, reflecting the prevalence of better file systems.)

Related