Search code examples
cpointersfunctionmacrosparentheses

Access a function pointer without parenthesis


I have this code:

#include <stdio.h>

int getAns(void);
int num;

int main() 
{
    int (*current_ans)(void);
    current_ans = &getAns;
    // HERE
    printf("%d", current_ans());    

}

int getAns()
{
    return num + 3;
}

However, is it possible to have something in the // HERE spot that allows the next line to be printf("%d", current_ans); which accesses getAns() in a roundabout way?


Solution

  • I suspect you can not , because the () is necessary to tell the compiler it is an function call. However, if you really want to do it,you can do :

    #define current_ans current_ans()