|
| From: | Avi Kivity |
| Subject: | Re: [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmissing-prototypes |
| Date: | Tue, 12 Aug 2008 12:22:27 +0300 |
| User-agent: | Thunderbird 2.0.0.16 (X11/20080723) |
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
| [Prev in Thread] | Current Thread | [Next in Thread] |