More on function pointers

This article is a follow up to: Introduction to using function pointers in C (or C++)

There’s a trick make life a bit easier when dealing with function pointers. We can typedef the function. In the previous article we used a feedback function. Let’s take it from there.

We prototyped our feedback function like this:

int (*feedback_fun)(char *str) ;

Instead we can create a new type of function like the above by using typedef like this:

typedef int (*feedback_ptr)(char *str);

Doing this we can make the function declarations look nicer. We can declare a variable holding a pointer to the feedback functions like this:

feedback_ptr feedback_fun ;

Nice isn’t it? But we haven’t won that much. We have to wait until we dive into plugins until we see the benefits if this.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s