https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109214
Bug ID: 109214
Summary: extension to C language allowing void * to be cast
to function pointer should be documented
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: rouca at debian dot org
Target Milestone: ---
Hi,
according to POSIX
https://pubs.opengroup.org/onlinepubs/009696899/functions/dlsym.html
"The ISO C standard does not require that pointers to functions can be cast
back and forth to pointers to data. Indeed, the ISO C standard does not require
that an object of type void * can hold a pointer to a function. Implementations
supporting the XSI extension, however, do require that an object of type void *
can hold a pointer to a function. The result of converting a pointer to a
function into a pointer to another data type (except void *) is still
undefined, however. Note that compilers conforming to the ISO C standard are
required to generate a warning if a conversion from a void * pointer to a
function pointer is attempted as in:
fptr = (int (*)(int))dlsym(handle, "my_function");"
This extension should be documented in the C, C++ extension documentation.
Moreover maybe adding a type attribute in order to clear the warning for this
kind of function may also help [1]
Bastien
[1] https://stackoverflow.com/questions/31526876/casting-when-using-dlsym