GNU 标准库命名约定

GNU standard library naming conventions

当我查看 GNU 库(好吧,主要是 libstdc++)的实现时,我可以看到命名中有重复出现的模式。模板类型被命名为 _Tp,成员有前置 _M_,一些标记有前置双下划线等。我试图找到关于命名约定的文档,但无济于事。 GNU 有一个样式指南,代码中也遵循它,但更像是该命名约定的子集。

您知道关于 GNU gcc 库实现的样式细节的任何文档吗?

提前致谢。

下划线不是 "coding convention" 而是为了避免与用户定义的宏等名称冲突

来自 https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html(这实际上适用于 libc,但我认为它也适用于 libstdc++):

In addition to the names documented in this manual, reserved names include all external identifiers (global functions and variables) that begin with an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names. This is so that the library and header files can define functions, variables, and macros for internal purposes without risk of conflict with names in user programs.

GNU 网站还提供了更多关于进一步保留名称的信息。 另请参阅 this 问题的答案。看起来 C++ 标准本身规定了命名约定。

更新:

OP 请求的信息似乎有点分散在不同的页面上。我将尝试总结以下最重要的几点:

首先,可以找到有关 _T_M_ 等名称的信息 here

摘录:

For nonstandard names appearing in Standard headers, we are constrained to use names that begin with underscores. This is called "uglification". The convention is: [...]

Type names and template formal-argument names: _[A-Z][^_].*

Examples: _Helper _CharT _N

Member data and function names: _M_.*

Examples: _M_num_elements _M_initialize ()

Static data members, constants, and enumerations: _S_.*

Examples: _S_max_elements _S_default_value

进一步挖掘将我带到 libstdc++ contributing page,它说:

The GNU C++ Library is part of GCC and follows the same development model, so the general rules for contributing to GCC apply.

按照上面 link,您将到达 GNU GCC 贡献页面,其中显示(在编码标准下)

All contributions must conform to the GNU Coding Standards. There are also some additional coding conventions for GCC; these include documentation and testsuite requirements as well as requirements on code formatting.

Submissions which do not conform to the standards will be returned with a request to address any such problems. To help with the preparation of patches you can use the script contrib/check_GNU_style.sh.

这最终会导致 GCC Coding Conventions,这是一般准则。

我希望这能提供一些更好的信息。