为什么不是所有的标准 headers 前面都有 std 前缀?

Why not all the standard headers are preceded with std prefix?

为什么不是所有的标准 headers 都以 std 前缀开头? IE。为什么 complex.h 而不是 stdcomplex.h

为什么?为什么不?谁知道?构成 标准 库的头文件开始演变为该主题的类别 before a standard existed, over years of revisions by developers and scrutiny by C committee members. Many of the original authors and committee members who developed and canonized these files are now part of the big compiler in the sky and not available to answer the question "why" the standard naming convention is not really conventional or standard. But reading this wiki page 至少可以让您了解一些历史和背景。

从历史上看,命名与正式的 ISO 标准化没有任何关系,我认为从来没有人想在所有标准库面前扔 std

最早提到的标准库似乎是 K&R The C programming Language 1978 年的第 1 版,我们可以在第 8.5 章下方阅读:

The data structure that describes a file is contained in the file stdio.h, which must be included (by #include) in any source file that uses routines from the standard library.

值得注意的是,K&R 将其称为 标准库 ,而不是标准 input/output 库。所以也许(这是猜测)这个 header 最初打算成为 C 的整个标准库。这是我在书中提到的当前 ISO 标准库 header 中唯一的一个并pre-dates正式标准化十余年。

然后在 ANSI/ISO 标准化过程中,headers stdargstddefstdiostdlib 被添加到第一个标准,但这些只是 15 个使用 std 前缀的标准 header 中的 4 个。各种 C 或 Unix de-facto 标准 header 被添加到标准中几乎是任意的。任何事情都没有合理的理由,尤其是 API 或命名。他们只是将各种已经存在的“可有可无”的 Unix 库放入标准中。

值得注意的是,原始 C 标准仅保证标准 header 的 6 个唯一字母,并且所有原始 header 的名称都包含 6 个或更少的字母。这在 C99 中扩展为 8 个字母。

C99延续了随意命名的传统,增加了一大堆新的header,其中只有stdintstdbool有std前缀。 C11 命名大多数带有 std 前缀的新 header 可能受到 C++ 的一些影响,但值得注意的是 C11 还添加了没有前缀的 uchar.h