Hemanth Hemanth - 8 days ago 6
C Question

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

typedef int (fc_name) (void);


Here
fc_name
is any valid C symbol.

How different is this from a function pointer
typedef
?

Answer

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;
Comments