Determining to which function a pointer is pointing in C?

后端 未结 9 1009
情话喂你
情话喂你 2021-02-01 12:25

I have a pointer to function, assume any signature. And I have 5 different functions with same signature.

At run time one of them gets assigned to the pointer, and that

9条回答
  •  佛祖请我去吃肉
    2021-02-01 13:08

    Generally, in C such things are not available to the programmer.

    There might be system-specific ways of getting there by using debug symbols etc., but you probably don't want to depend on the presence of these for the program to function normally.

    But, you can of course compare the value of the pointer to another value, e.g.

    if (ptr_to_function == some_function)
        printf("Function pointer now points to some_function!\n");
    

提交回复
热议问题