I'm trying to understand function declaration using typedefs.
What does this code do in C++?
typedef void fcn_t(void);
typedef void (*ptr_t)(void);
fcn_t f;
fcn_t *pf;
ptr_t pf2;
In my understanding:
fcn_tis the type of a function, and so the line withfis a function declaration (not a definition), and I could later define it likevoid f(void) { blabla(); bleble(); }just as if I had declaredvoid f(void);instead offcn_t f;;fcn_t *is the type of a function pointer, and the line withpfis a pointer variable definition, andpfis default-initialized (assuming the code excerpt is from the global scope);- There is no difference between
fcn_t*andptr_t, thus everything I said aboutpfapplies topf2.
Did I get it right? Would any of the three declarations have its meaning changed if I marked them extern? What would change if the code was compiled as C instead of as C++?