1

I've seen a typedef operation in the following format in signal function's man page:

   #include <signal.h>

   typedef void (*sighandler_t)(int);

   sighandler_t signal(int signum, sighandler_t handler);

What is (*sighandler_t)(int); Is it a function pointer or alternate option for using void? How it can be used?

Thank you.

2
typedef void (*sighandler_t)(int);

defines sighandler_t as a pointer type to a function whose return type is void and takes an int as an argument.

the name of a function, just like the name of an array, decays to a pointer to a function. you could use it like that

void foo(int x)
{
    // some code
}

// some code
sighandler_t p = foo; // p points to foo
p(10); // call foo through p

see http://www.cprogramming.com/tutorial/function-pointers.html!

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .