Formally, no, you cannot do this, but in practice, yes. To be called from C code, the C ++ function must be labeled extern "C" to ensure that it uses the calling convention that C compiler expects. It is not possible to mark a static member function as extern "C" , therefore it cannot be guaranteed that it can be successfully called from C code. I do not know a compiler that does not use the same calling convention for static member functions as for C code, so this will work. Some compilers give a warning for this situation, because technically the function is of the wrong type. In fact, if you look at the C ++ standard, C functions that accept callbacks (like qsort , for example) have two versions: one that accepts an extern "C" function and a function that accepts an extern "C++" function.
source share