3 ms·
It’s not a warning, it’s a compile time error and I am not even using -Wall -Werror I also believe there are platforms where a function pointer and a data poin
by akdev1l 1y ago
It’s not a warning, it’s a compile time error and I am not even using -Wall -Werror
I also believe there are platforms where a function pointer and a data pointer are not the same but idk about such esoteric platforms first hand (seems Itanium had that: https://stackoverflow.com/questions/36645660/why-cant-i-cast-a-function-pointer-to-void https://stackoverflow.com/questions/36645660/why-cant-i-cast...)
Though my point was only that this code will not compile as is with whatever clang Apple ships*
I am not really sure how to get it to compile tbqh
Some further research ( https://www.kdab.com/how-to-cast-a-function-pointer-to-a-void/ https://www.kdab.com/how-to-cast-a-function-pointer-to-a-voi...) suggest it should be done like so:
> auto fptr = &f; void a = reinterpret_cast<void &>(fptr);
edit: I tried with GCC 15 and that compiled successfully
- comex 1y agoIt should just be res.fn = (void *)fn; `res.fn` is of type `void *`, so that's what the code should be casting to. Casting to `func0Ptr` there seems to just be a mistake. Some compilers may allow the resulting function pointer to then implicitly convert to `void *`, but it's not valid in standard C++, hence the error. Separately from that, if you enable -Wpedantic, you can get a warning for conversions between function and data pointers even if they do use an explicit cast, but that's not the default.
- gpderetta 1y agoFWIW, POSIX practically requires void otr and function otr inter-convertibility hence the support from GCC.
- wahern 1y agoNot practically, but literally: Note that conversion from a void * pointer to a function pointer as in: fptr = (int (*)(int))dlsym(handle, "my_function"); is not defined by the ISO C standard. This standard requires this conversion to work correctly on conforming implementations.
- gpderetta 1y agoI remembered the dlsym requirement, I wasn't sure it was de-jure.