最近我看了很多 C 语言的套接字编程教程。在每个视频中,都包含头文件 sys/types
,但是当我运行编写的代码时在没有 sys/types 的视频中,我没有收到任何警告或错误。这个头文件有什么作用以及为什么如此常见?
最佳答案
该文件定义了其他文件中使用的许多类型。在较旧的系统上,有必要将其包含在其他系统 header 之前。
来自 socket
系统调用的手册页:
SYNOPSIS
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
...
NOTES
POSIX.1 does not require the inclusion of <sys/types.h>, and this
header file is not required on Linux. However, some historical (BSD)
implementations required this header file, and portable applications
are probably wise to include it.
关于c - 为什么我看到的每个编程教程中都无缘无故地包含 sys/types ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61446189/