在Tanenbaum的MINIX手册中描述的MINIX 3的源代码中,include/signal.h和sys/types.h中都出现了typedef void _PROTOTYPE( (*sighandler_t),(int) );
行,为什么要定义两次呢?
编辑:在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) );
完整的文件可以找到here
最佳答案
为什么要定义两次?
……因为人类是容易犯错的。这似乎只是一个错误/遗漏。Minix 3是一个不断发展的项目,这个bug最终得到了修复。
关于c - 在两个头文件中定义的相同类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51369695/