Received: from eggs.gnu.org ([2001:4830:134:3::10]:51028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdQgy-0000hY-0F for qemu-devel@nongnu.org; Mon, 04 Nov 2013 15:24:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VdQgs-0001AR-Jl for qemu-devel@nongnu.org; Mon, 04 Nov 2013 15:24:07 -0500 Message-ID: <5278025D.1000201@weilnetz.de> Date: Mon, 04 Nov 2013 21:23:57 +0100 From: Stefan Weil MIME-Version: 1.0 References: <1383594685-19332-1-git-send-email-sw@weilnetz.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] gtk: Fix compiler warnings with -Werror=sign-compare List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Trivial , qemu-devel , Anthony Liguori Am 04.11.2013 21:07, schrieb Peter Maydell: > On 4 November 2013 19:51, Stefan Weil wrote: >> With -Werror=3Dsign-compare (not enabled by default), gcc shows these = errors: >> >> ui/gtk.c: In function =E2=80=98gtk_release_modifiers=E2=80=99: >> ui/gtk.c:288:19: error: >> comparison between signed and unsigned integer expressions [-Werror=3D= sign-compare] >> ui/gtk.c: In function =E2=80=98gd_key_event=E2=80=99: >> ui/gtk.c:746:19: error: >> comparison between signed and unsigned integer expressions [-Werror=3D= sign-compare] > If this warning is going to complain about entirely > safe and idiomatic code like > > int i; > static const int some_array[] =3D { > 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd, > }; > > for (i =3D 0; i < ARRAY_SIZE(some_array); i++) { > ... > } > > then I think it is more trouble than it is worth and we > should leave it disabled. > > thanks > -- PMM Yes, we should leave it disabled for simple practical reasons: there are too many warnings of this kind, so I don't expect they will be fixed in the near future (I have no plan to send patches to fix them all - this one was just in my way). And yes, we should fix code which can be improved as easily as in the above example. ARRAY_SIZE happens to be an unsigned size_t, so comparing it to an unsigned value is better IMHO (I'm aware that there were already discussions about using signed or unsigned integers). -Wsign-compare is like other compiler warnings: it can detect some really unwanted code, but a human reviewer won't always agree on the results.It might be a good idea to support it somewhere in the far future= . Stefan