的typedef
在這種情況下是排序手短的用於返回void
和接受3個參數(int
,siginfo_t *
和void *
)的函數。這主要用於如果你想傳遞一個函數作爲回調的例子。
void func1(sa_sigaction_t handler)
{
handler(...);
}
func1
調用sa_sigaction_t
類型的任何功能。你可以把它像這樣:
void func2(int a, siginfo_t * b, void * c)
{
...
}
int main(void)
{
func1(func2);
/*
* Equivalent to:
* sa_sigaction_t handler = func2;
* func1(func2);
*/
return 0;
}
在另一方面,如果你沒有足夠的typedef
,你的代碼會更詳細:
void func1(void(*handler)(int, siginfo_t *, void*))
{
handler(...);
}
void func2(int a, siginfo_t * b, void * c)
{
...
}
int main(void)
{
func1(func2);
/*
* Equivalent to:
* void(*handler)(int, siginfo_t *, void*) = func2;
* func1(func2);
*/
return 0;
}
一些需要注意的是,有時你會看到func2
和其他時間&func2
,但這些都是同樣的事情。