c - 为什么我看到的每个编程教程都无缘无故地包含 sys/types?
问题描述
最近我一直在看很多 C 的套接字编程教程。在每个视频中,sys/types
都包含头文件,但是当我运行视频中编写的没有 . 的代码时sys/types
,我没有收到任何警告或错误。这个头文件有什么作用,为什么如此普遍?
解决方案
该文件定义了其他文件中使用的许多类型。在旧系统上,有必要在其他系统头文件之前包含它。
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.
推荐阅读
- ios - 自定义绘图 UIView 在 iOS 9 上崩溃但在其他系统上工作
- node.js - 如何通过云功能删除所有匿名用户?
- javascript - 使用 Ajax POST 请求将数据发送到 Flask 后端
- angular - 角业力茉莉花日期比较
- java - Elasticsearch 排序 - 没有得到预期的结果
- html - 如何添加 X 微调型汉堡菜单
- xmpp - XMPP:如何在客户端之间发送自定义消息?
- python - 基于当前行和上一行的用户定义函数
- google-cloud-firestore - Firestore 安全规则授予用户对文档及其子集合的读/写权限不起作用
- python - 有时在 Firefox 中找不到定位器