The C++ Standard contains the following rule in section 16.2, Source File Inclusion. It makes single-character file extension special somehow.
c++标准在第16.2节“源文件包含”中包含了以下规则。它使单字符文件扩展名变得特殊。
The implementation shall provide unique mappings for sequences consisting of one or more nondigits or digits (2.11) followed by a period (
.
) and a single nondigit. The first character shall not be a digit. The implementation may ignore distinctions of alphabetical case.实现应该为由一个或多个非数字或数字(2.11)、一个句点(.)和一个非数字组成的序列提供唯一的映射。第一个字符不能是数字。实现可以忽略字母大小写的区别。
What special treatment do these filenames get? What is a mapping in context of header file inclusion, and why does it matter if it is unique?
这些文件名有什么特殊处理?在头文件包含的上下文中,什么是映射?如果它是唯一的,为什么会有关系呢?
1 个解决方案
#1
4
It is saying, in the roundabout standardese way, that header files such as "abyssinia.h"
shall be mapped to a unique file name in the file system, even if the underlying file system doesn't support 9.1 file names — think of old-style DOS with the 8.3 limitation, or the oldest versions of Unix that had a maximum of 14 characters for a file name. The system has to ensure that such names are mapped uniquely to different files.
它以迂回的标准方式表示,头文件如“abyssinia”。h"应该映射到文件系统中唯一的文件名,即使底层文件系统不支持9.1文件名——请考虑具有8.3限制的旧式DOS,或者Unix最老的版本,其文件名最多有14个字符。系统必须确保这些名称被唯一地映射到不同的文件。
It also says that the implementation may ignore case (which also means that it may not ignore case). If it does ignore case, then "ABYSSINIA.H"
and "abyssinia.h"
will map to the same file; if it does not ignore case, then they will be two separate files. Note that Windows and Mac OS X both have case-preserving but case-insensitive file systems, at least by default.
它还说实现可能会忽略case(这也意味着它可能不会忽略case)。如果它确实忽略了case,那么“ABYSSINIA”。H”和“阿比西尼亚。h"将映射到同一个文件;如果它不忽略大小写,那么它们将是两个独立的文件。注意,Windows和Mac OS X都有大小写保留但不区分大小写的文件系统,至少在默认情况下是如此。
I'm not sure why the single non-digit restriction is present; it presumably means the the .hpp
extension is not guaranteed to map to unique names.
我不知道为什么会出现单个位数限制;它可能意味着.hpp扩展不能保证映射到唯一的名称。
This is all a constraint on the implementation; it mostly doesn't affect you as a programmer (unless you're a programmer writing the implementation — meaning the implementation of a C++ compiler), except that you should probably ensure that your header names are unique regardless of case, and for maximal portability, your header names should end .h
or some other single-letter extension.
这都是对实现的限制;是不会影响你作为一个程序员(除非你是一个程序员编写的实现——这意味着实现c++编译器),除了你应该确保你的头的名字是独一无二的,不管情况下,最大的可移植性,你的标题名称应该结束. h或其他单字符的扩展。
#1
4
It is saying, in the roundabout standardese way, that header files such as "abyssinia.h"
shall be mapped to a unique file name in the file system, even if the underlying file system doesn't support 9.1 file names — think of old-style DOS with the 8.3 limitation, or the oldest versions of Unix that had a maximum of 14 characters for a file name. The system has to ensure that such names are mapped uniquely to different files.
它以迂回的标准方式表示,头文件如“abyssinia”。h"应该映射到文件系统中唯一的文件名,即使底层文件系统不支持9.1文件名——请考虑具有8.3限制的旧式DOS,或者Unix最老的版本,其文件名最多有14个字符。系统必须确保这些名称被唯一地映射到不同的文件。
It also says that the implementation may ignore case (which also means that it may not ignore case). If it does ignore case, then "ABYSSINIA.H"
and "abyssinia.h"
will map to the same file; if it does not ignore case, then they will be two separate files. Note that Windows and Mac OS X both have case-preserving but case-insensitive file systems, at least by default.
它还说实现可能会忽略case(这也意味着它可能不会忽略case)。如果它确实忽略了case,那么“ABYSSINIA”。H”和“阿比西尼亚。h"将映射到同一个文件;如果它不忽略大小写,那么它们将是两个独立的文件。注意,Windows和Mac OS X都有大小写保留但不区分大小写的文件系统,至少在默认情况下是如此。
I'm not sure why the single non-digit restriction is present; it presumably means the the .hpp
extension is not guaranteed to map to unique names.
我不知道为什么会出现单个位数限制;它可能意味着.hpp扩展不能保证映射到唯一的名称。
This is all a constraint on the implementation; it mostly doesn't affect you as a programmer (unless you're a programmer writing the implementation — meaning the implementation of a C++ compiler), except that you should probably ensure that your header names are unique regardless of case, and for maximal portability, your header names should end .h
or some other single-letter extension.
这都是对实现的限制;是不会影响你作为一个程序员(除非你是一个程序员编写的实现——这意味着实现c++编译器),除了你应该确保你的头的名字是独一无二的,不管情况下,最大的可移植性,你的标题名称应该结束. h或其他单字符的扩展。