[nycbug-talk] That crazy typedef

Tim A. techneck at goldenpath.org
Thu Apr 3 17:38:31 EDT 2008

We bounced this around a little last night.
First line of code presented in "Designing BSD Rootkits" (by Joseph 
Kong) is the
Prototype for the module event handler function as defined in 
sys/module.h FreeBSD source header

typedef int (*modeventhand_t) (module_t, int /* modeventtype_t */, void * );

At first it didn't make any sense. But I was, like, ok! there's only so 
much you can do with a typedef!

Brushing up on my C recently, this just seemed a more complex kind of 
typedef than I'm used to.
Checking the C Pocket Reference did not help, but as Marc pointed out 
K&R had the answer.
Actually, a nearly identical example.

If I am now understanding it correctly,
the statement creates the type modeventhand_t as a pointer to function 
returning int and taking three arguments,
(that inline comment threw me off at first).

Just thought I'd share that for anyone else who was curious about it.

And, please, correct me if I'm wrong.

More information about the talk mailing list