POSIX和C语言有什么关系?
What is the relationship between POSIX and the C language?
我理解C语言是一个ISO standard, and I can see from Wikipedia that the standard includes 29 header files,按照这些头文件,C应用程序理论上是'portable'.
然而,实际上,我最近尝试在 simple C HTTP server 上做一个教程,它使用不属于 C 标准的头文件。因此,在这种情况下,我能想到的最简单的应用程序 - 包含单个 int main(void)
函数的 C 应用程序,并且少于 100 行,目的是在网络接口上进行监听,这超出了 C 标准?
在这种情况下,作为规范的 C 语言与(假设我正在为 Linux 编写应用程序)作为语言的 POSIX 规范之间的关系是什么?
据我所知,"man7.org" 提供了定义所有 Unix/Linux 系统的 API 的 C 头文件列表(我假设这是相同的作为 'POSIX') 系统,以及 Linux 平台的系统调用列表。
这包括 82 个头文件,其中 29 个 C 标准库头文件是一个子集,以及大约 10 000 个系统调用(至少我假设 this list 中不是头文件的所有内容都是系统调用)。
我假设任何用 C 语言编写的功能合理的程序都将超越标准库并使用 OS 特定的头文件。如果说在 Linux 上将应用程序编程到 运行 实际上是 "POSIX programming" 不是更准确吗?
我想也可以坚持使用标准库,并为跨 POSIX 和非 POSIX 系统(包括平台)的可移植逻辑实现定义自定义头文件-特定的汇编例程)。有没有做过?
POSIX 不是一种语言的规范,它是一种 操作系统的规范 ,只是其中的一部分是更广泛的 C 库规范和其他对 C 语言本身需要如何在此类操作系统上实现的限制。
有许多流行的 cross-platform 库。 POSIX C 规范最关心的领域的一个流行库是 Apache Portable Runtime:
The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.
APR 包括 sockets and threads and processes 之类的内容,可用于为各种操作系统编译相同的应用程序 - 许多 unix-like 和 Windows - 只需很少的更改。
POSIX 不是标准,而是 标准家族 指定了整个操作系统。
POSIX C 标准是标准 C 库的超集,这两者之间的关系在 this other question
中有详细描述
我理解C语言是一个ISO standard, and I can see from Wikipedia that the standard includes 29 header files,按照这些头文件,C应用程序理论上是'portable'.
然而,实际上,我最近尝试在 simple C HTTP server 上做一个教程,它使用不属于 C 标准的头文件。因此,在这种情况下,我能想到的最简单的应用程序 - 包含单个 int main(void)
函数的 C 应用程序,并且少于 100 行,目的是在网络接口上进行监听,这超出了 C 标准?
在这种情况下,作为规范的 C 语言与(假设我正在为 Linux 编写应用程序)作为语言的 POSIX 规范之间的关系是什么?
据我所知,"man7.org" 提供了定义所有 Unix/Linux 系统的 API 的 C 头文件列表(我假设这是相同的作为 'POSIX') 系统,以及 Linux 平台的系统调用列表。
这包括 82 个头文件,其中 29 个 C 标准库头文件是一个子集,以及大约 10 000 个系统调用(至少我假设 this list 中不是头文件的所有内容都是系统调用)。
我假设任何用 C 语言编写的功能合理的程序都将超越标准库并使用 OS 特定的头文件。如果说在 Linux 上将应用程序编程到 运行 实际上是 "POSIX programming" 不是更准确吗?
我想也可以坚持使用标准库,并为跨 POSIX 和非 POSIX 系统(包括平台)的可移植逻辑实现定义自定义头文件-特定的汇编例程)。有没有做过?
POSIX 不是一种语言的规范,它是一种 操作系统的规范 ,只是其中的一部分是更广泛的 C 库规范和其他对 C 语言本身需要如何在此类操作系统上实现的限制。
有许多流行的 cross-platform 库。 POSIX C 规范最关心的领域的一个流行库是 Apache Portable Runtime:
The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.
APR 包括 sockets and threads and processes 之类的内容,可用于为各种操作系统编译相同的应用程序 - 许多 unix-like 和 Windows - 只需很少的更改。
POSIX 不是标准,而是 标准家族 指定了整个操作系统。
POSIX C 标准是标准 C 库的超集,这两者之间的关系在 this other question
中有详细描述