[Spice-devel] [PATCH 05/11] make red_pipe_item_init_full more typesafe

Christophe Fergeau cfergeau at redhat.com
Mon May 23 09:48:45 UTC 2016


> > I don't find this very readable, and imo there is not a huge gain in
> > doing this over a cast... I'd just go with a cast + a static
> > compile-time assert that RedCursorPipeItem has a 'base' RedPipeItem
> > field at offset 0.
> > 
> 
> static void cursor_pipe_item_free(RedPipeItem *base)
> {
>    spice_return_if_fail(base);
> 
>    verify(SPICE_OFFSETOF(RedCursorPipeItem, base) == 0);
>    RedCursorPipeItem *pipe_item = (RedCursorPipeItem *) base;
>    ...
> 
> (obviously for every cast)

I'd put it next to the structure definition and forget about it

typedef struct RedCursorPipeItem {
    RedPipeItem base;
    CursorItem *cursor_item;
} RedCursorPipeItem;

verify(SPICE_OFFSETOF(RedCursorPipeItem, base) == 0);

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160523/c2ab67a1/attachment-0001.sig>


More information about the Spice-devel mailing list