qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmis


From: Laurent Vivier
Subject: Re: [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmissing-prototypes
Date: Mon, 11 Aug 2008 22:03:33 +0200

Le lundi 11 août 2008 à 14:22 -0500, Anthony Liguori a écrit :
> Laurent Vivier wrote:
> >
> >>
> >> I vote for this. The other solutions do not improve type safety
> >> (except for union) and they are more complex.
> >
> > But I think to call the function you have to cast the pointer, this 
> > doesn't improve type safety too...
> 
> Right now, the monitor works by taking a generic function pointer "void 
> (*)()" which is treated specially by the C standard (although it's now 
> deprecated).  Any function pointer can be cast to a generic function 
> pointer.  The dispatch loop basically looks like:
> 
> void dispatch(void (*func)(), int n_args, void *args)
> {
>     switch (n_args) {
>     case 1:
>         ((void (*)(void *))func)(args[0]); break;
>     case 1:
>         ((void (*)(void *, void *))func)(args[0]); break;
>     ...
> }
> 
> But this tosses a warning since void (*)() is deprecated.  So, if we use:
> 
> void dispatch(void *func, int n_args, void *args)
> 
> It'll work just like it did before.
> 

but using "void (*handler)(int argc, char** argv)" avoids the switch:

switch(nb_args) {
    case 0:
        cmd->handler();
        break;
    case 1:
        cmd->handler(args[0]);
        break;
...
}

becomes

cmd->handler(nb_args, args);

Laurent

-- 
----------------- address@hidden  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry





reply via email to

[Prev in Thread] Current Thread [Next in Thread]