Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Ive seen different syntax used for calling functions via pointers. Whats the story?

0
Posted

Ive seen different syntax used for calling functions via pointers. Whats the story?

0

Originally, a pointer to a function had to be “turned into” a “real” function, with the * operator, before calling: int r, (*fp)(), func(); fp = func; r = (*fp)(); The interpretation of the last line is clear: fp is a pointer to function, so *fp is the function; append an argument list in parentheses (and extra parentheses around *fp to get the precedence right), and you’ve got a function call. It can also be argued that functions are always called via pointers, and that “real” function names always decay implicitly into pointers (in expressions, as they do in initializations; see question 1.34). This reasoning means that r = fp(); is legal and works correctly, whether fp is the name of a function or a pointer to one. (The usage has always been unambiguous; there is nothing you ever could have done with a function pointer followed by an argument list except call the function pointed to.) The ANSI C Standard essentially adopts the latter interpretation, meaning that the explicit *

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123