[vlc-devel] Callbacks in modules written in C++ have wrong linkage

Rémi Denis-Courmont remi at remlab.net
Mon Feb 22 21:48:03 CET 2016

Le 2016-02-22 21:59, Filip Roséen a écrit :
>> Yes and no. ISO C leaves it as a portability issue what conversion
>> what function and void pointers do, but somewhat recommends
>> supporting it for debugging purpose anyway.
> I did not know that; what revision of the standard and which section?
> I am happy to learn new stuff.
>> Win32 & OpenGL use a different style: void (_)() instead of void _.
> The ISO C++ Standard (N3797), and I really thought ISO C did the 
> same,
> considers this to be _undefined-behavior_ and have no clause related
> to debugging purposes.
> Using void(*)() instead of void* is in my book far better because of
> two main reasons:

I must disagree. We have had a lot of issues with missing or incomplete 
function prototypes on 64-bits platforms in the past.

> An implementation is allowed to store code and memory in completely
> different manners, as such there is nothing saying that a
> _pointer-to-function_ and _pointer-to-void_ are compatible.

We do not require void pointers to be compatible with function 
pointers. We only require that a function pointer can be reversibly 
stored in a void pointer. In other words, we require that the conversion 
from function pointer to void pointer be an injective function.

That is by design true for Von Neumann architectures, which is what 
everybody uses. Even on a Harvard architectures, this is required to 
implement dlsym().

> The likelyhood of different types of function-pointers having the 
> same
> size is far greater than sizeof(void*) == sizeof(void(*)()).

No, I have yet to see a real life general purpose architecture where 
this wouldn't hold. But we do not require that anyway.

Rémi Denis-Courmont

More information about the vlc-devel mailing list