Determining to which function a pointer is pointing in C?

后端 未结 9 1006
情话喂你
情话喂你 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:21

    This is utterly awful and non-portable, but assuming:

    1. You're on Linux or some similar, ELF-based system.
    2. You're using dynamic linking.
    3. The function is in a shared library or you used -rdynamic when linking.
    4. Probably a lot of other assumptions you shouldn't be making...

    You can obtain the name of a function by passing its address to the nonstandard dladdr function.

提交回复
热议问题