From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KSq5I-0000vS-Um for qemu-devel@nongnu.org; Tue, 12 Aug 2008 05:22:33 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KSq5H-0000tN-1A for qemu-devel@nongnu.org; Tue, 12 Aug 2008 05:22:32 -0400 Received: from [199.232.76.173] (port=40741 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KSq5G-0000sy-FA for qemu-devel@nongnu.org; Tue, 12 Aug 2008 05:22:30 -0400 Received: from il.qumranet.com ([212.179.150.194]:16293) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KSq5F-0003vL-8L for qemu-devel@nongnu.org; Tue, 12 Aug 2008 05:22:30 -0400 Message-ID: <48A15653.2090107@qumranet.com> Date: Tue, 12 Aug 2008 12:22:27 +0300 From: Avi Kivity MIME-Version: 1.0 Subject: Re: [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmissing-prototypes References: <489DE0C7.9000505@codemonkey.ws> <48A04ACD.5090900@codemonkey.ws> <48A05150.2040405@qumranet.com> <48A0533A.9020707@codemonkey.ws> <48A06B12.5000701@qumranet.com> <48A06D07.60103@codemonkey.ws> <48A09168.6000301@codemonkey.ws> <1218485013.3865.2.camel@frecb07144> <48A0EE09.90904@codemonkey.ws> In-Reply-To: <48A0EE09.90904@codemonkey.ws> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Blue Swirl , Laurent Vivier Anthony Liguori wrote: > Laurent Vivier wrote: >> Le lundi 11 ao=C3=BBt 2008 =C3=A0 14:22 -0500, Anthony Liguori a =C3=A9= crit : >> =20 >> 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); >> =20 > > 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 =3D 0; > > if (argc =3D=3D 2) { > if (strcmp(argv[0], "-f") =3D=3D 0) { > force =3D 1; > device =3D argv[1]; > } else { > term_printf("bad option %s\n", argv[0]); > return; > } > } else if (argc =3D=3D 1) { > device =3D argv[0]; > } else { > term_printf("bad number of options\n"); > return; > } > > ... > } > > Consider multiplying that by all of the possible monitor commands, and=20 > it's totally not worth it. > I forgot about non-string args. So the transformation would be: void do_eject(void **args) { int *force =3D *(int *)args[0]; const char *device =3D *(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 =3D args++->i; const char *device =3D args++->s; ... } ) --=20 error compiling committee.c: too many arguments to function