You can compare a pointer to a function with a pointer to a function. Like this:
if (fp==add) printf("\nadd\n");
There are no other (standard) methods 1 .
it
printf("\n%s\n",*fp);
- compilation error.
There are certain platforms. For linux, this works:
#include<stdio.h> #include <execinfo.h> int add(int i,int j) { printf("\n%s\n",__FUNCTION__); return (i*j); } int (*fp)(int,int); union { int (*fp)(int,int); void* fp1; } fpt; int main() { fp=add; fpt.fp=fp; char ** funName = backtrace_symbols(&fpt.fp1, 1); printf("%s\n",*funName); }
source share