qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>,
	Laurent Vivier <Laurent.Vivier@bull.net>
Subject: Re: [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmissing-prototypes
Date: Tue, 12 Aug 2008 12:22:27 +0300	[thread overview]
Message-ID: <48A15653.2090107@qumranet.com> (raw)
In-Reply-To: <48A0EE09.90904@codemonkey.ws>

Anthony Liguori wrote:
> Laurent Vivier wrote:
>> Le lundi 11 août 2008 à 14:22 -0500, Anthony Liguori a écrit :
>>  
>> 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);
>>   
>
> And then every monitor command changes from:
>
> void do_eject(int force, char *device)
> {
>     ...
> }
>
> to:
>
> void do_eject(int argc, char **argv)
> {
>   char *device;
>   int force = 0;
>
>   if (argc == 2) {
>     if (strcmp(argv[0], "-f") == 0) {
>         force = 1;
>         device = argv[1];
>     } else {
>         term_printf("bad option %s\n", argv[0]);
>         return;
>     }
>  } else if (argc == 1) {
>      device = argv[0];
>  } else {
>      term_printf("bad number of options\n");
>      return;
>  }
>
>  ...
> }
>
> Consider multiplying that by all of the possible monitor commands, and 
> it's totally not worth it.
>


I forgot about non-string args.  So the transformation would be:

void do_eject(void **args)
{
    int *force = *(int *)args[0];
    const char *device = *(const char **)args[1];

   ...
}

But this isn't really an improvement, apart from dropping the ugly switch.

(maybe a union:

typedef union {
    int i;
    const char *s;
    ...
} Arg;

void do_eject(const Args *args)
{
    int force = args++->i;
    const char *device = args++->s;

    ...
}

)

-- 
error compiling committee.c: too many arguments to function

  parent reply	other threads:[~2008-08-12  9:22 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
2008-08-12  1:57                       ` Anthony Liguori
2008-08-12  8:14                         ` Laurent Vivier
2008-08-12  9:22                         ` Avi Kivity [this message]
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=48A15653.2090107@qumranet.com \
    --to=avi@qumranet.com \
    --cc=Laurent.Vivier@bull.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).