c - 两个头文件中定义的相同类型
问题描述
在 Tanenbaum 的 MINIX 书中描述的 MINIX 3 的源代码中,该行typedef void _PROTOTYPE( (*sighandler_t),(int) );
出现在include/signal.h和sys/types.h中。为什么要定义两次?
编辑:在sys/types.h一些周围的代码是:
#ifndef _TYPES_H
#define _TYPES_H
#ifndef _ANSI_H
#include <ansi.h>
#endif
/* ........(too long to write)....... */
#if _EM_WSIZE == 2
/*typedef unsigned int Ino_t; Ino_t is now 32 bits */
typedef unsigned int Zone1_t;
typedef unsigned int Bitchunk_t;
typedef unsigned int Bitchunk_t;
typedef unsigned int U16_t;
typedef unsigned int _mnx_Mode_t;
#else /* _EM_WSIZE == 4, or _EM_WSIZE undefined */
/* typedef int Ino_t; Ino_t is now 32 bits */
typedef int Zone1_t;
typedef int Bitchunk_t;
typedef int U16_t;
typedef int _mnx_Mode_t;
#endif /* _EM_WSIZE == 2, etc */
/* Signal handler type, e.g. SIG_IGN */
typedef void _PROTOTYPE( (*sighandler_t), (int) );
在include/signal.h中:
#ifndef _ANSI_H
#include <ansi.h>
#endif
#ifdef _POSIX_SOURCE
#ifndef _TYPES_H
#include <sys/types.h>
#endif
#endif
/* .......(too long to write)....... */
/* POSIX requires the following signals to be defined, even if they are
* not supported. Here are the definitions, but they are not supported.
*/
#define SIGCONT 18 /* continue if stopped */
#define SIGSTOP 19 /* stop signal */
#define SIGTSTP 20 /* interactive stop signal */
#define SIGTTIN 21 /* background process wants to read */
#define SIGTTOU 22 /* background process wants to write */
/* The sighandler_t type is not allowed unless _POSIX_SOURCE is defined. */
typedef void _PROTOTYPE( (*__sighandler_t), (int) );
完整的文件可以在这里找到
解决方案
为什么要定义两次?
...因为人类是容易犯错的。这似乎只是一个错误/遗漏。Minix 3 是一个不断发展的项目,该错误最终得到了修复。
推荐阅读
- sql - 如何减少我的 sql 的基数和成本
- html - NetSuite:FreeMarker/BFO 图像在分页时被切断
- javascript - 未定义对象数组中的“this”值
- reactjs - React Antt 设计可编辑表以添加日期选择器不起作用
- c++ - Esp8266 和 Internet FTP 客户端的密码?
- angular - 可观察对象的动态数组与 switchMap 函数串联运行,一旦全部完成,即使有些失败也运行
- linux - 无法使用 bash 文件获取打印输出
- sass - 使用插值连接 SASS 变量名称
- python - sklearn TheilSenRegressor ValueError 在为一维回归量设置 fit_intercept=False 时
- c - VisualStudio Cmake IoT 目标交叉编译.exe 添加到程序名称