Reputation: 24880
What is the difference between the following function typedef
:
typedef void tbl_opt (void *tbl_item, void *tbl_param); // 1
typedef void *tbl_opt (void *tbl_item, void *tbl_param); // 2
typedef void (*tbl_opt) (void *tbl_item, void *tbl_param); // 3
typedef (void *) (*tbl_opt) (void *tbl_item, void *tbl_param); // 4
Usually, I use the 3rd & 4th, but I saw the other 2 in a book, which I don't understand well.
[Update] Summary:
It seems when define type in case 1 or 2, when use that type, still need declare a pointer variable, and initialize it to point to another actual function, so I guess that's why case 3 & 4 are more popular.
Upvotes: 1
Views: 75
Reputation: 408
3 and 4 are Function Pointers:
A Function that returns void or nothing and takes two void* arguments
typedef void tbl_opt (void *tbl_item, void *tbl_param);
A function that returns a void* and takes two void * arguments
typedef void *tbl_opt (void *tbl_item, void *tbl_param);
A function pointer to a function that returns void or nothing and takes two void* arguments
typedef void (*tbl_opt) (void *tbl_item, void *tbl_param);
A Function pointer to a function that returns void* and takes two void* arguments
typedef (void *) (*tbl_opt) (void *tbl_item, void *tbl_param);
Upvotes: 4
Reputation: 3312
typedef to:
by the way, please read Reading C Type Declarations - it will change your life.
Upvotes: 4