This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
首先,当注册信号处理程序时,此时不应调用该函数。相反,需要一个指向函数的指针:该指针存储在 sigaction 结构中:
我们需要函数本身,而不是函数调用的返回值。
其次,该函数必须具有适合信号处理程序的类型:
请注意,在 C 语言中,与 C++ 不同,如果将函数参数列表声明为
()
,则该函数将声明为具有未知的参数类型信息。函数定义是一个不带参数的函数,与(void)
兼容,但作为声明,它不会向周围的程序说明这一点。Firstly, when a signal handler is registered, the function isn't supposed to be called at that time. Rather, a pointer to the function is required: the pointer is stored into the
sigaction
structure:We want the funtion itself, not the return value from a call to the function.
Secondly, the function has to have the right type for a signal handler:
Note that in the C language, unlike C++, if you declare a function paramter list as
()
, it declares the function as having an unknown parameter type information. The function definition is one that takes no arguments, compatible with(void)
, but as a declaration it doesn't say that to the surrounding program.而不是像这样的语句
以及
使用具有返回类型 void 的函数调用
您需要编写并
分配函数指针,
。注意,例如数据成员sa_handler具有类型,
因此相应的函数应具有相同的类型。
从文档中
Instead of statements like these
and
where there are used function calls that have the return type void you need to write
and
to assign function pointers.
Pay attention to that for example the data member
sa_handler
has the typeSo the corresponding function shall have the same type.
From the documentation