15

I don't understand the meaning of typedef void interrupt_handler();. Could someone explain it with some examples?

typedef void interrupt_handler();
Kevin
  • 53,822
  • 15
  • 101
  • 132

2 Answers2

19

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;
}
Grzegorz Szpetkowski
  • 36,988
  • 6
  • 90
  • 137
  • I have this function void cpu_boot(uint cores, interrupt_handler bootfunc, uint serialno) and in argument bootfunc i want to pass the following arguments: Task boot_task, int argl, void* args. Task is type typedef int (* Task)(int, void*); How can i implement it? something like wrapper function? @cmbasnett – Lefteris Sarantaris Dec 15 '14 at 00:30
  • @LefterisSarantaris: I would rather ask it in separate question. Don't forget to describe what you have already tried, explain your issue and add some minimal example of it. – Grzegorz Szpetkowski Dec 15 '14 at 00:38
9

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)

Community
  • 1
  • 1
Colin Basnett
  • 4,052
  • 2
  • 30
  • 49