Hemanth Hemanth - 1 year ago 74
C Question

What does a typedef with parenthesis like "typedef int (f)(void)" mean? Is it a function prototype?

typedef int (fc_name) (void);

is any valid C symbol.

How different is this from a function pointer

Answer Source

It's a typedef to a function type. The intent is to use it for function pointers, but in this case the syntax to use it would be:

int bar(void);

fc_name* foo = bar; /* Note the * */

Update: As mentioned in the comments to Jonathan Leffler's answer, the typedef can be used to declare functions. One use could be for declaring a set of callback functions:

typedef int (callback)(int, void*);

callback onFoo;
callback onBar;
callback onBaz;
callback onQux;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download