C标准库和C POSIX库之间的区别 [英] Difference between C standard library and C POSIX library

查看:2138
本文介绍了C标准库和C POSIX库之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C标准库和C POSIX LIB有点困惑,因为我发现,在C POSIX lib目录中定义很多头文件也都是C标准库的一部分。

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标准库是由ANSI C的组织定义一个lib,并有不同的平台上不同的实现的(Win32 /类Unix),和C POSIX LIB仅仅是一个执行C标准库的类Unix操作系统,对吧?

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 POSIX lib目录中包含一些头在C标准库未指定,如< SYS / types.h中> < SYS / wait.h> < pthreads.h中方式>

But "C POSIX lib" contains some headers not specified in "C standard lib", such as <sys/types.h>, <sys/wait.h>, and <pthread.h>.

&LT; pthreads.h中&GT; 作为一个例子,我presume其C标准库对应的是&LT;线程。 H&GT; ,那么如果我想要写Linux上的多线程程序,这头文件,我应该包括&LT; pthreads.h中&GT; &LT; threads.h&GT;

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>?

推荐答案

POSIX标准C库的一个超集,并且要注意的是它委托给它,它是非常重要的。如果C和POSIX是有史以来发生冲突,C赢了。

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库中不存在。

Sockets, file descriptors, shared memory etc. are all part of POSIX, but do not exist in the C library.

pthreads.h中用于POSIX线程和 threads.h 是C11的新报头,是部分C库。也许pthreads的将是支持C的人在将来的某个时候pcated德$ P $,但你可能不能指望C11有wides $ P $垫部署呢。因此,如果你想可移植性,你应该preFER pthreads的现在。如果便携性是不是一个问题,你有可用的C11线程,你应该使用这些。

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.

这篇关于C标准库和C POSIX库之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆