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

Hemanth picture Hemanth · Sep 9, 2010 · Viewed 16.6k times · Source
typedef int (fc_name) (void);

Here fc_name is any valid C symbol.

How different is this from a function pointer typedef?

Answer

jamesdlin picture jamesdlin · Sep 9, 2010

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;