I’m using a C library (from C++) which provides the following interface:
void register_callback(void* f, void* data);
void invoke_callback(
POSIX recommends the following way to cast between function pointer types and object pointer types (which is undefined in C99):
typedef void function_type(void*);
function_type *p_to_function = &my_callback;
void* p_to_data = *(void**)&p_to_function;
// Undefined:
// void* p_to_data = (void*)p_to_function;
Notice that in C++-land, this would perform a reinterpret_cast from function_type**. This is not undefined but instead implementation-defined, unlike reinterpret_cast. So it's probably your best bet to write C++-conformant code that relies on the implementation.