Re: Dodgy function pointer casts

Tuomo Valkonen <[email protected]>
Newsgroups gmane.comp.window-managers.ion.general
Message-ID <[email protected]>
On 2007-04-26, Ben Hutchings <ben-/[email protected]> wrote:
>> Umm... any kind of OO shit in C absolutely positively depends on
>> function pointer casts.
>
> I haven't noticed this being necessary in the GObject system.  It does
> rely on data pointer casts, but those are fine.

G-shit just hides casts in A_ZILLION_AWFUL_MACROS_WITH_UNMANAGEABLE_NAMES.

Anyway, the _FooClass structures contain function pointers for the 
pseudo-dynamic functions. The first parameter is of type Foo*. A 
subclass Bar must fill these in. Obviously in the subclass's 
implementation of these functions, the first parameter is Bar*. 
Ion's _much_ more usable object system, on the other hand, uses 
a table of mappings {dynfun, implementation}, so that it isn't 
necessary to fill in complex hierarchies of structures: you just
list the functions that you do implement. It actually needs
_less_ explicit casts than the G-shit, because the function 
pointers in the structure are of type void (*)(), which any
function 'returning' void can be implicitly cast to. Functions
that do not return a void, need (DynFun*) explicit casts, however.
Cast of 'void (*)(Bar*)' to 'void (*)(Foo*)' must always be explicit.

-- 
Tuomo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.