I know that there are rules for using underscores in identifiers in C/C++. Are there any rules for using them in source code filenames?
For instance, are there any restrictions against beginning or ending a filename with an underscore? Or having an underscore as the last character before the .c
or .h
extension? Double underscores?
References are appreciated, if there are any.
If the source files are subject for preprocessor #include
directives, then the C and C++ standards specify a minimum set of requirements on the filename. The C standard says:
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. The implementation may ignore distinctions of alphabetical case and restrict the mapping to eight significant characters before the period.
... where nondigit contains the letters A-Z, a-z and underscore.
The exact same text (except for the paragraph numbers) can also be found in the C++ standard, 16.2 Source file inclusion.
Beyond that, what passes for a valid filename depends on the operating system, file system, compiler, linker and other parts of the compilation tool chain.
These days, I'd expect most modern systems to allow almost anything that isn't directly forbidden by the file system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With