I don't understand the meaning of typedef void interrupt_handler();
. Could someone explain it with some examples?
typedef void interrupt_handler();
I don't understand the meaning of typedef void interrupt_handler();
. Could someone explain it with some examples?
typedef void interrupt_handler();
It means that interrupt_handler
is type synonym for function, that returns void
and does not specify its parameters (so called old-style declaration). See following example, where foo_ptr
is used as function pointer (this is special case where parentheses are not needed):
#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;
}
It's a typedef
declaration of a function pointer with a particular signature (in this case a function with a void
return and no arguments).
See What is a C++ delegate? (top answer, option 3)