I don't understand the meaning of typedef void interrupt_handler();
. Could someone explain it with some examples?
typedef void interrupt_handler();
As a return “type”. In the function declaration void foo(int) , the void signifies that “ foo does not return a value”.
typedef void (*MCB)(void); This is one of the areas where there is a significant difference between C, which does not - yet - require all functions to be prototyped before being defined or used, and C++, which does.
typedef is a reserved keyword in the programming languages C and C++. It is used to create an additional name (alias) for another data type, but does not create a new type, except in the obscure case of a qualified typedef of an array type where the typedef qualifiers are transferred to the array element type.
typedef is a language construct that associates a name to a type. myinteger i; // is equivalent to int i; mystring s; // is the same as char *s; myfunc f; // compile equally as void (*f)(); As you can see, you could just replace the typedefed name with its definition given above.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With