gpt4 book ai didi

c++ - C++标准库和POSIX等系统接口(interface)标准有什么关系?

转载 作者:搜寻专家 更新时间:2023-10-31 00:11:32 26 4
gpt4 key购买 nike

最近同事问我Dinkumware C++标准库是否支持POSIX,我不知道怎么回答。对我来说,不清楚两者之间的关系是什么。

C++ 标准库是否提供 POSIX 接口(interface)的实现?或者这两者实际上是两个独立的东西,彼此不相关但可以在开发过程中串联使用?

我做了一些谷歌搜索,但无法真正得出任何结论。有这篇文章描述了 POSIX 和标准 C 之间的区别,但是 C++ 标准库呢? Difference Between POSIX and Standard C Library

任何启发将不胜感激!

最佳答案

whether Dinkumware C++ standard library supports POSIX ... To me it is not clear what is the relation between the two.

POSIX 是操作系统接口(interface)的标准。 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;...

关于c++ - C++标准库和POSIX等系统接口(interface)标准有什么关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33776503/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com