4

Possible Duplicate:
How come pointer to a function be called without dereferencing?
How does dereferencing of a function pointer happen?

Supposing I have a function pointer like:

void fun() { /* ... */ };
typedef void (* func_t)();
func_t fp = fun;

Then I can invoke it by:

fp();

or

(*fp)();

What is the difference/

Community
  • 1
  • 1
pipipi
  • 501
  • 1
  • 3
  • 11

1 Answers1

7

Precisely two parentheses and an asterisk.

Both call the function pointed to by fun, and both do so in the same manner.

However, visually, (*fun) makes it clear that fun is not a function in and of itself, and the dereference operator is a visual cue that it is a pointer of some kind.

The without-parentheses syntax, fun(), is the same as a regular function call and so visually equates to that, making it primarily clear you're calling some kind of function. It takes context or a lookup to notice that it is a function pointer.

This is just a style difference, as far as what happens.

ssube
  • 47,010
  • 7
  • 103
  • 140