首页 > 解决方案 > 两个头文件中定义的相同类型

问题描述

在 Tanenbaum 的 MINIX 书中描述的 MINIX 3 的源代码中,该行typedef void _PROTOTYPE( (*sighandler_t),(int) );出现在include/signal.hsys/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) );

完整的文件可以在这里找到

标签: cheader-filesminix

解决方案


为什么要定义两次?

...因为人类是容易犯错的。这似乎只是一个错误/遗漏。Minix 3 是一个不断发展的项目,该错误最终得到了修复。


推荐阅读