All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <Laurent.Vivier@bull.net>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Blue Swirl <blauwirbel@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmissing-prototypes
Date: Mon, 11 Aug 2008 22:03:33 +0200	[thread overview]
Message-ID: <1218485013.3865.2.camel@frecb07144> (raw)
In-Reply-To: <48A09168.6000301@codemonkey.ws>

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

-- 
----------------- Laurent.Vivier@bull.net  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry

  reply	other threads:[~2008-08-11 20:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-08 17:22 [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmissing-prototypes Blue Swirl
2008-08-09 18:24 ` Anthony Liguori
2008-08-10 18:33   ` Blue Swirl
2008-08-11  7:52     ` Gerd Hoffmann
2008-08-11  9:54       ` Samuel Thibault
2008-08-11 13:32         ` M. Warner Losh
2008-08-11 13:30       ` M. Warner Losh
2008-08-11 14:21     ` Anthony Liguori
2008-08-11 14:48       ` Avi Kivity
2008-08-11 14:53         ` Paul Brook
2008-08-11 14:56         ` Laurent Vivier
2008-08-11 14:56         ` Anthony Liguori
2008-08-11 16:38           ` Avi Kivity
2008-08-11 16:47             ` Anthony Liguori
2008-08-11 18:52               ` Blue Swirl
2008-08-11 18:57                 ` Laurent Vivier
2008-08-11 19:11                   ` Blue Swirl
2008-08-11 19:22                   ` Anthony Liguori
2008-08-11 20:03                     ` Laurent Vivier [this message]
2008-08-12  1:57                       ` Anthony Liguori
2008-08-12  8:14                         ` Laurent Vivier
2008-08-12  9:22                         ` Avi Kivity
2008-08-12 12:24                     ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1218485013.3865.2.camel@frecb07144 \
    --to=laurent.vivier@bull.net \
    --cc=anthony@codemonkey.ws \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.