Firstly, the question is: is there a reason why you cannot take the address of a function from this function?
#include <stdio.h>
struct foo {
void(*xf)(void);
int r;
} sFoo;
void func(void) {
sFoo.xf = func;
}
int main()
{
func();
printf("FuncPtr is: %p\n", sFoo.xf);
printf("FuncAddr is: %p\n", &func);
getchar();
return 0;
}
I cannot think of the reason why this should not work portable, but that does not mean that it does not exist. I tested it with MinGW and MSVC on Windows, and gcc on Ubuntu, and it works great. Standard C is almost silent, except that (C99 5.1.1.2) function references are resolved in the final translation phase.
, , , . , , , , , , .