什么才是1号在SIG_IGN宏定义的含义是什么? [英] What 's the meaning of the number 1 in SIG_IGN macro definition?

查看:449
本文介绍了什么才是1号在SIG_IGN宏定义的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#define SIG_IGN     (void (*)(int))1
#define SIG_HOLD    (void (*)(int))5
#define SIG_ERR     ((void (*)(int))-1)

我知道什么是(无效(*)(INT))表示:投unknown_name到函数指针(INT)返回void

I know what (void (*)(int)) means: cast unknown_name into pointer to function (int) returning void.

但是,什么是意义以下 1

But what's the meaning of the following 1?

的常数被使用,以便它可以从一个有效的函数指针来区分

解决方案

推荐答案

例如:

#define SIG_DFL ((__sighandler_t)0)     /* default signal handling */
#define SIG_IGN ((__sighandler_t)1)     /* ignore signal */
#define SIG_ERR ((__sighandler_t)-1)    /* error return from signal */

这些常数值都不是东西,你可以调用一个有效的函数地址。因此,他们是因为这可以用来表示如何处理信号的特殊值是有用的。

None of those constant values is something that you could call as a valid function address. So they are useful as special values that can be used to say how to handle signals.

POSIX的方式并没有提到这些常量 1 0 1 ,preferring才说出的符号常量的(在预期的地方,反正)的 < signal.h中方式>

POSIX by the way does not mention these constants -1, 0 or 1, preferring to say only symbolic constants (in the expected place, anyway): <signal.h>.

延伸阅读:

  • executing default signal handler
  • 24.3.1 Basic Signal Handling (The GNU C library)

这篇关于什么才是1号在SIG_IGN宏定义的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆