Lef*_*ris 15 c typedef variable-declaration function-declaration
我不明白的意思typedef void interrupt_handler();
.有人可以用一些例子解释一下吗?
typedef void interrupt_handler();
Run Code Online (Sandbox Code Playgroud)
Grz*_*ski 19
这意味着它interrupt_handler
是函数的类型同义词,它返回void
并且不指定其参数(所谓的旧式声明).请参阅以下示例,其中where foo_ptr
用作函数指针(这是不需要括号的特殊情况):
#include <stdio.h>
typedef void interrupt_handler();
void foo()
{
printf("foo\n");
}
int main(void)
{
void (*foo_ptr_ordinary)() = foo;
interrupt_handler *foo_ptr = foo; // no need for parantheses
foo_ptr_ordinary();
foo_ptr();
return 0;
}
Run Code Online (Sandbox Code Playgroud)