Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KSdcD-0004Oy-LT for qemu-devel@nongnu.org; Mon, 11 Aug 2008 16:03:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KSdcB-0004Ma-Ey for qemu-devel@nongnu.org; Mon, 11 Aug 2008 16:03:40 -0400 Received: from [199.232.76.173] (port=49611 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KSdcB-0004MJ-6m for qemu-devel@nongnu.org; Mon, 11 Aug 2008 16:03:39 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:45937) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KSdcA-0004Yc-Rz for qemu-devel@nongnu.org; Mon, 11 Aug 2008 16:03:39 -0400 Subject: Re: [Qemu-devel] [RFC, PATCH] Add -Wstrict-prototypes, maybe later -Wmissing-prototypes From: Laurent Vivier In-Reply-To: <48A09168.6000301@codemonkey.ws> 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> Content-Type: text/plain; charset=utf-8 Date: Mon, 11 Aug 2008 22:03:33 +0200 Message-Id: <1218485013.3865.2.camel@frecb07144> Mime-Version: 1.0 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: Anthony Liguori Cc: Blue Swirl , qemu-devel@nongnu.org Le lundi 11 ao=C3=BBt 2008 =C3=A0 14:22 -0500, Anthony Liguori a =C3=A9cr= it : > 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=20 > > doesn't improve type safety too... >=20 > Right now, the monitor works by taking a generic function pointer "void= =20 > (*)()" which is treated specially by the C standard (although it's now=20 > deprecated). Any function pointer can be cast to a generic function=20 > pointer. The dispatch loop basically looks like: >=20 > 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; > ... > } >=20 > But this tosses a warning since void (*)() is deprecated. So, if we us= e: >=20 > void dispatch(void *func, int n_args, void *args) >=20 > It'll work just like it did before. >=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); Laurent --=20 ----------------- Laurent.Vivier@bull.net ------------------ "La perfection est atteinte non quand il ne reste rien =C3=A0 ajouter mais quand il ne reste rien =C3=A0 enlever." Saint Exup=C3=A9ry