I'm a little confused by "C standard lib" and "C POSIX lib", because I found that, many header files defined in "C POSIX lib" are also part of "C standard lib".
我对“C标准库”和“C标准库”有点迷惑,因为我发现,“C标准库”中定义的许多头文件也是“C标准库”的一部分。
So, I assume that, "C standard lib" is a lib defined by ANSI C organization, and there are different implementation on different platforms (Win32/Unix-like), and "C POSIX lib" is just a implementation for "C standard lib" on Unix-like OSes, right?
因此,我假设,“C标准库”是由ANSI C组织定义的库,不同平台上有不同的实现(Win32/ unix类),而“C POSIX lib”只是unix类os上的“C标准库”的实现,对吧?
But "C POSIX lib" contains some headers not specified in "C standard lib", such as <sys/types.h>
, <sys/wait.h>
, and <pthread.h>
.
但是“C POSIX lib”包含一些在“C标准lib”中没有指定的头,比如
Take <pthread.h>
as an example, I presume its "C standard lib" counterpart is <threads.h>
, then if I want to write a multi-threaded program on Linux, which header file should I include, <pthread.h>
or <threads.h>
?
< pthread。以h>为例,假设它的“C标准库”对应项是
3 个解决方案
#1
36
POSIX is a superset of the standard C library, and it's important to note that it defers to it. If C and POSIX is ever in conflict, C wins.
POSIX是标准C库的超集,需要注意的是,它与标准C库是一致的。如果C和POSIX发生冲突,C获胜。
Sockets, file descriptors, shared memory etc. are all part of POSIX, but do not exist in the C library.
套接字、文件描述符、共享内存等都是POSIX的一部分,但是在C库中不存在。
pthread.h
is used for POSIX threads and threads.h
is a new header for C11 and is part of the C library. Perhaps pthreads will be deprecated sometime in the future in favor of the C ones, however you probably can't count on C11 to have widespread deployment yet. Therefore if you want portability you should prefer pthreads for now. If portability is not a concern, and you have C11 threads available, you should probably use those.
pthread。h用于POSIX线程和线程。h是C11的一个新头,是C库的一部分。也许在将来的某个时候,pthreads会被弃用以支持C语言,但是您可能还不能指望C11具有广泛的部署。因此,如果您想要可移植性,您现在应该更喜欢pthreads。如果不关心可移植性,并且您有C11线程可用,那么您可能应该使用它们。
#2
9
The C POSIX library is a specification of a C standard library for POSIX systems. It was developed at the same time as the ANSI C standard. Some effort was made to make POSIX compatible with standard C; POSIX includes additional functions to those introduced in standard C.
C POSIX库是POSIX系统的C标准库的规范。它与ANSI C标准同时开发。为使POSIX与标准C兼容做了一些努力;POSIX包括在标准C中引入的附加功能。
#3
3
POSIX 7 quote
POSIX 7报价
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap01.html#tag_14_01
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap01.html tag_14_01
1.1 Relationship to Other Formal Standards
1.1与其他正式标准的关系
Great care has been taken to ensure that this volume of POSIX.1-2008 is fully aligned with the following standards:
为确保这一数量的POSIX.1-2008完全符合下列标准,已采取了非常谨慎的措施:
ISO C (1999) 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.
ISO C (1999) ISO/IEC 9899:1999,编程语言- C,包括ISO/IEC 9899:1999/Cor.1:2001(E), ISO/IEC 9899:1999/Cor.2:2004(E), ISO/IEC 9899:1999/Cor.3。
Parts of the ISO/IEC 9899:1999 standard (hereinafter referred to as the ISO C standard) are referenced to describe requirements also mandated by this volume of POSIX.1-2008. Some functions and headers included within this volume of POSIX.1-2008 have a version in the ISO C standard; in this case CX markings are added as appropriate to show where the ISO C standard has been extended (see Codes). Any conflict between this volume of POSIX.1-2008 and the ISO C standard is unintentional.
ISO/IEC 9899:1999标准(以下简称ISO C标准)的部分内容用于描述由posix .1 .1-2008卷规定的要求。在POSIX.1-2008卷中包含的一些函数和标头具有ISO C标准中的版本;在这种情况下,根据需要添加CX标记,以显示ISO C标准的扩展位置(参见代码)。这卷POSIX.1-2008和ISO C标准之间的任何冲突都是无意的。
I have listed some major API extensions at: I never really understood: what is POSIX?
我在以下列出了一些主要的API扩展:我从未真正理解:POSIX是什么?
#1
36
POSIX is a superset of the standard C library, and it's important to note that it defers to it. If C and POSIX is ever in conflict, C wins.
POSIX是标准C库的超集,需要注意的是,它与标准C库是一致的。如果C和POSIX发生冲突,C获胜。
Sockets, file descriptors, shared memory etc. are all part of POSIX, but do not exist in the C library.
套接字、文件描述符、共享内存等都是POSIX的一部分,但是在C库中不存在。
pthread.h
is used for POSIX threads and threads.h
is a new header for C11 and is part of the C library. Perhaps pthreads will be deprecated sometime in the future in favor of the C ones, however you probably can't count on C11 to have widespread deployment yet. Therefore if you want portability you should prefer pthreads for now. If portability is not a concern, and you have C11 threads available, you should probably use those.
pthread。h用于POSIX线程和线程。h是C11的一个新头,是C库的一部分。也许在将来的某个时候,pthreads会被弃用以支持C语言,但是您可能还不能指望C11具有广泛的部署。因此,如果您想要可移植性,您现在应该更喜欢pthreads。如果不关心可移植性,并且您有C11线程可用,那么您可能应该使用它们。
#2
9
The C POSIX library is a specification of a C standard library for POSIX systems. It was developed at the same time as the ANSI C standard. Some effort was made to make POSIX compatible with standard C; POSIX includes additional functions to those introduced in standard C.
C POSIX库是POSIX系统的C标准库的规范。它与ANSI C标准同时开发。为使POSIX与标准C兼容做了一些努力;POSIX包括在标准C中引入的附加功能。
#3
3
POSIX 7 quote
POSIX 7报价
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap01.html#tag_14_01
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap01.html tag_14_01
1.1 Relationship to Other Formal Standards
1.1与其他正式标准的关系
Great care has been taken to ensure that this volume of POSIX.1-2008 is fully aligned with the following standards:
为确保这一数量的POSIX.1-2008完全符合下列标准,已采取了非常谨慎的措施:
ISO C (1999) 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.
ISO C (1999) ISO/IEC 9899:1999,编程语言- C,包括ISO/IEC 9899:1999/Cor.1:2001(E), ISO/IEC 9899:1999/Cor.2:2004(E), ISO/IEC 9899:1999/Cor.3。
Parts of the ISO/IEC 9899:1999 standard (hereinafter referred to as the ISO C standard) are referenced to describe requirements also mandated by this volume of POSIX.1-2008. Some functions and headers included within this volume of POSIX.1-2008 have a version in the ISO C standard; in this case CX markings are added as appropriate to show where the ISO C standard has been extended (see Codes). Any conflict between this volume of POSIX.1-2008 and the ISO C standard is unintentional.
ISO/IEC 9899:1999标准(以下简称ISO C标准)的部分内容用于描述由posix .1 .1-2008卷规定的要求。在POSIX.1-2008卷中包含的一些函数和标头具有ISO C标准中的版本;在这种情况下,根据需要添加CX标记,以显示ISO C标准的扩展位置(参见代码)。这卷POSIX.1-2008和ISO C标准之间的任何冲突都是无意的。
I have listed some major API extensions at: I never really understood: what is POSIX?
我在以下列出了一些主要的API扩展:我从未真正理解:POSIX是什么?