C++标准库和POSIX这样的系统接口标准有什么关系?
What is the relation between C++ standard library and system interface standards like POSIX?
最近同事问我Dinkumware C++标准库是否支持POSIX,我不知道怎么回答。我不清楚这两者之间的关系。
C++ 标准库是否提供 POSIX 接口的实现?或者这两者实际上是两个独立的东西,彼此不相关但可以在开发过程中串联使用?
我用谷歌搜索了一下,但无法得出任何结论。有这篇文章描述了 POSIX 和标准 C 之间的区别,但是 C++ 标准库呢?
Difference Between POSIX and Standard C Library
如有指教,将不胜感激!
我会说 C++ 标准库和 C 标准库在同一级别上运行。这意味着您会发现这些实用程序允许执行潜在的复杂操作,但对底层的要求很少 OS - 确切地说,因为它们必须可移植到所有体系结构中。
Posix 另一边处理 OS 层。所以恕我直言,参考文章中几乎所有内容也适用于 C++ 标准库。主要区别在于它现在是 C++ 库与 C Posix 库,这意味着在除了可移植性之外,您还可以获得类型控制、覆盖和所有其他 C++ 优点。
whether Dinkumware C++ standard library supports POSIX ... To me it is not clear what is the relation between the two.
POSIX是操作系统接口的标准。 C++标准库不是操作系统,所以这个问题需要细说
C++标准库不需要POSIX,POSIX不需要C++标准库。但是,C++ 标准需要一些东西才能与 POSIX:
兼容
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace posix or to a namespace within namespace posix unless otherwise specified. The namespace posix is reserved for use by ISO/IEC 9945 and other POSIX standards.
The global namespace posix is now reserved for standardization. Valid C ++ 2003 code that uses a top-level namespace posix may be invalid in this International Standard.
For operating systems that are based on POSIX, implementations are encouraged to define the std::system_category() values as identical to the POSIX errno values, with additional values as de- fined by the operating system’s documentation. Implementations for operating systems that are not based on POSIX are encouraged to define values identical to the operating system’s values. For errors that do not originate from the operating system, the implementation may provide enums for the associated values.
Calls to the POSIX functions setenv and putenv modify the environment.
The header <cerrno>
is described in Table 43. Its contents are the same as the POSIX header <errno.h>
, except that errno shall be defined as a macro. [ Note: The intent is to remain in close alignment with the POSIX standard. — end note ]
streamsize is used in most places where ISO C would use size_t. Most of the uses of streamsize could use size_t, except for the strstreambuf constructors, which require negative values. It should probably be the signed type corresponding to size_t (which is what Posix.2 calls ssize_t).
Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions.
虽然POSIX基于C标准库并遵从它,C标准库是C++语言规范的一部分,但C++标准库通常不实现C标准库。
另一方面,C 标准库可以实现 POSIX 需要的功能。 The New C Standard: An Economic and Cultural Commentary 的一些引述:
Some of the functions in the C library have the same name as functions defined by POSIX. POSIX, being an API-based standard (essentially a complete operating system) vendors have shown more interest in implementing the POSIX functionality.
Most hosted environments provide the full set of functionality specified here. The POSIX (ISO/IEC 9945) standard defines some of the functions in the C library. On the whole the specification of this functionality is a pure extension of the C specification.
The C Standard, unlike POSIX, does not prohibit the use of functions, macros, type definitions, and objects from other standards, but such libraries must not change the behavior of any of the C-defined library functionality.
On most implementations a byte occupies 8 bits. The POSIX Standard requires that CHAR_BIT have a value of 8. The Digital DEC 10 and Honeywell/Multics used a 36-bit word with the underlying storage organization based on 9-bit bytes. Some DSP chips have a 16- or 32-bit character type (this often has more to do with addressability issues than character set sizes).
Structure or union types defined in system headers are special in that development projects rarely have any control over their contents. The members of structure and union types defined in these system headers can vary between vendors. An example of the different structure members seen in the same structure type is provided by the dirent structure. The POSIX.1 Standard requires that this structure type include the members d_name and d_namelen. The Open Groups Single Unix Specification goes further and requires that the member d_ino must also be present. Looking at the system header on Linux we find that it also includes the members d_off and d_type;...
POSIX 通过引用具体合并了 2004 年之前的 C 标准:
The facilities provided in POSIX.1-2008 are drawn from the following base documents: […]
ISO/IEC 9899:1999, Programming Languages - C, including ISO/IEC 9899:1999/Cor.1:2001(E), ISO/IEC 9899:1999/Cor.2:2004(E), and ISO/IEC 9899:1999/Cor.3
它还加入了Fortran-78标准,没有定义系统接口,并表示“其他相关标准或未来版本可能会提供额外的语言绑定和开发实用程序选项。”在大多数实际系统中,只有一个 "C library" 包含来自两个标准的所有绑定。
Maxim Egorushkin 有一些试图与 POSIX 兼容的语言标准示例。
POSIX 的不寻常之处在于它为标准系统头文件添加了新的特性和保证。大多数系统库与标准库的分离程度远高于此:如果您为 Windows 编写程序,则同时包括 <windows.h>
和标准库头文件。 C 库函数 link 调用 MSVC 运行时 DLL,而系统调用 link 调用 KERNEL、GDI 等。不过,通常情况下,您需要同时使用编译器提供的系统库和标准库,并且link 到它的运行时。
最近同事问我Dinkumware C++标准库是否支持POSIX,我不知道怎么回答。我不清楚这两者之间的关系。
C++ 标准库是否提供 POSIX 接口的实现?或者这两者实际上是两个独立的东西,彼此不相关但可以在开发过程中串联使用?
我用谷歌搜索了一下,但无法得出任何结论。有这篇文章描述了 POSIX 和标准 C 之间的区别,但是 C++ 标准库呢? Difference Between POSIX and Standard C Library
如有指教,将不胜感激!
我会说 C++ 标准库和 C 标准库在同一级别上运行。这意味着您会发现这些实用程序允许执行潜在的复杂操作,但对底层的要求很少 OS - 确切地说,因为它们必须可移植到所有体系结构中。
Posix 另一边处理 OS 层。所以恕我直言,参考文章中几乎所有内容也适用于 C++ 标准库。主要区别在于它现在是 C++ 库与 C Posix 库,这意味着在除了可移植性之外,您还可以获得类型控制、覆盖和所有其他 C++ 优点。
whether Dinkumware C++ standard library supports POSIX ... To me it is not clear what is the relation between the two.
POSIX是操作系统接口的标准。 C++标准库不是操作系统,所以这个问题需要细说
C++标准库不需要POSIX,POSIX不需要C++标准库。但是,C++ 标准需要一些东西才能与 POSIX:
兼容The behavior of a C++ program is undefined if it adds declarations or definitions to namespace posix or to a namespace within namespace posix unless otherwise specified. The namespace posix is reserved for use by ISO/IEC 9945 and other POSIX standards.
The global namespace posix is now reserved for standardization. Valid C ++ 2003 code that uses a top-level namespace posix may be invalid in this International Standard.
For operating systems that are based on POSIX, implementations are encouraged to define the std::system_category() values as identical to the POSIX errno values, with additional values as de- fined by the operating system’s documentation. Implementations for operating systems that are not based on POSIX are encouraged to define values identical to the operating system’s values. For errors that do not originate from the operating system, the implementation may provide enums for the associated values.
Calls to the POSIX functions setenv and putenv modify the environment.
The header
<cerrno>
is described in Table 43. Its contents are the same as the POSIX header<errno.h>
, except that errno shall be defined as a macro. [ Note: The intent is to remain in close alignment with the POSIX standard. — end note ]streamsize is used in most places where ISO C would use size_t. Most of the uses of streamsize could use size_t, except for the strstreambuf constructors, which require negative values. It should probably be the signed type corresponding to size_t (which is what Posix.2 calls ssize_t).
Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions.
虽然POSIX基于C标准库并遵从它,C标准库是C++语言规范的一部分,但C++标准库通常不实现C标准库。
另一方面,C 标准库可以实现 POSIX 需要的功能。 The New C Standard: An Economic and Cultural Commentary 的一些引述:
Some of the functions in the C library have the same name as functions defined by POSIX. POSIX, being an API-based standard (essentially a complete operating system) vendors have shown more interest in implementing the POSIX functionality.
Most hosted environments provide the full set of functionality specified here. The POSIX (ISO/IEC 9945) standard defines some of the functions in the C library. On the whole the specification of this functionality is a pure extension of the C specification.
The C Standard, unlike POSIX, does not prohibit the use of functions, macros, type definitions, and objects from other standards, but such libraries must not change the behavior of any of the C-defined library functionality.
On most implementations a byte occupies 8 bits. The POSIX Standard requires that CHAR_BIT have a value of 8. The Digital DEC 10 and Honeywell/Multics used a 36-bit word with the underlying storage organization based on 9-bit bytes. Some DSP chips have a 16- or 32-bit character type (this often has more to do with addressability issues than character set sizes).
Structure or union types defined in system headers are special in that development projects rarely have any control over their contents. The members of structure and union types defined in these system headers can vary between vendors. An example of the different structure members seen in the same structure type is provided by the dirent structure. The POSIX.1 Standard requires that this structure type include the members d_name and d_namelen. The Open Groups Single Unix Specification goes further and requires that the member d_ino must also be present. Looking at the system header on Linux we find that it also includes the members d_off and d_type;...
POSIX 通过引用具体合并了 2004 年之前的 C 标准:
The facilities provided in POSIX.1-2008 are drawn from the following base documents: […]
ISO/IEC 9899:1999, Programming Languages - C, including ISO/IEC 9899:1999/Cor.1:2001(E), ISO/IEC 9899:1999/Cor.2:2004(E), and ISO/IEC 9899:1999/Cor.3
它还加入了Fortran-78标准,没有定义系统接口,并表示“其他相关标准或未来版本可能会提供额外的语言绑定和开发实用程序选项。”在大多数实际系统中,只有一个 "C library" 包含来自两个标准的所有绑定。
Maxim Egorushkin 有一些试图与 POSIX 兼容的语言标准示例。
POSIX 的不寻常之处在于它为标准系统头文件添加了新的特性和保证。大多数系统库与标准库的分离程度远高于此:如果您为 Windows 编写程序,则同时包括 <windows.h>
和标准库头文件。 C 库函数 link 调用 MSVC 运行时 DLL,而系统调用 link 调用 KERNEL、GDI 等。不过,通常情况下,您需要同时使用编译器提供的系统库和标准库,并且link 到它的运行时。