I have two functions
void foo1(int);
void foo2(int);
i.e. both have the same signature. I have a function pointer
typedef void (*func_pt)(int)
that can point to either foo1 or foo2 e.g.
if (match_condition) {
func_pt = foo1;
}
else {
func_pt = foo2;
}
Later in the code, I need to find out if func_pt is pointing to foo1 or foo2.
This code if (func_pt == foo1)
seems to work.
Is this recommended and safe? If not, is there any alternative to findng out which function does a function pointer point to?
I don't understand how C compiler can figure out the equality. Is it just that the when the compiler sees foo1, it finds the address of the code where the function instructions are stored?
Thanks for any answers