how do the following function pointer multiple dereferences compile?

Viewed 44

I know with function pointers, you can call the function equivalently either using

 (*fptr)();
 //or 
 fptr(); 

But how do compilers achieve this? Do they completely disregard the reference token, or is there something more involved here?

Consider this valid c++ code:

void f1() { std::cout << "hi\n"; }
int main() {
    auto f = f1;
    (********************f1)();
    (*(*(*f1)))();
    ***************f1;
}

Are all the deference operators simply ignored?

And why is it not symmetrical with taking the address of functions? Here you may refer to a function with & or without, but you cannot use multiple & signs.

For example:

auto pf1 = f1; // ok
auto pf2 = &f1; // ok 
//  auto pf3 = &(&(f1)); // does not compile
0 Answers
Related