Function pointers casting in C++

前端 未结 8 1396
星月不相逢
星月不相逢 2020-11-27 15:45

I have a void pointer returned by dlsym(), I want to call the function pointed by the void pointer. So I do a type conversion by casting:

void *gptr = dlsym(         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 16:17

    Note that C++11 allows such a conversion and from gcc 4.9 and above this conversion does not generate a warning: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57869.

    See SO discussions:

    • Casts between pointer-to-function and pointer-to-object in C and C++
    • Why are function pointers and data pointers incompatible in C/C++?
    • can void* be used to store function pointers?
    • Using reinterpret_cast to cast a function to void*, why isn't it illegal?

提交回复
热议问题