What is the difference between fun (...) and (* fun) (...) using a function pointer in C / C ++

Possible duplicate:
How to find function pointer without dereferencing? How is dereferencing a function pointer?

Suppose I have a function pointer:

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

Then I can call it:

 fp(); 

or

 (*fp)(); 

What is the difference/

+4
source share
1 answer

Exactly two parentheses and an asterisk.

Both function calls fun points to, and both do it the same way.

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

The syntax without parentheses, fun() , is the same as a regular function call, and therefore visually equates to one that makes it primarily clear that you are calling some kind of function. A context or search is required to notice that it is a pointer to a function.

It’s just a difference in style as far as this happens.

+7
source

Source: https://habr.com/ru/post/1379578/


All Articles