From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51803 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oq7Jn-00018t-Nv for qemu-devel@nongnu.org; Mon, 30 Aug 2010 12:34:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oq7FC-0004eF-DV for qemu-devel@nongnu.org; Mon, 30 Aug 2010 12:30:07 -0400 Received: from mail-qy0-f173.google.com ([209.85.216.173]:42523) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oq7FC-0004e9-A3 for qemu-devel@nongnu.org; Mon, 30 Aug 2010 12:30:02 -0400 Received: by qyk5 with SMTP id 5so3104369qyk.4 for ; Mon, 30 Aug 2010 09:30:01 -0700 (PDT) Message-ID: <4C7BDC84.9070906@codemonkey.ws> Date: Mon, 30 Aug 2010 11:29:56 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH 10/14] Zero json struct with memset() instea of = {} to keep compiler happy. References: <1283182547-26116-1-git-send-email-Jes.Sorensen@redhat.com> <1283182547-26116-11-git-send-email-Jes.Sorensen@redhat.com> <4C7BD16F.1030301@redhat.com> <4C7BD926.3030704@codemonkey.ws> <4C7BD9DE.8090102@redhat.com> In-Reply-To: <4C7BD9DE.8090102@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: kwolf@redhat.com, Jes.Sorensen@redhat.com, qemu-devel@nongnu.org On 08/30/2010 11:18 AM, Paolo Bonzini wrote: > On 08/30/2010 06:15 PM, Anthony Liguori wrote: >> On 08/30/2010 10:42 AM, Paolo Bonzini wrote: >>> On 08/30/2010 05:35 PM, Jes.Sorensen@redhat.com wrote: >>>> - JSONParsingState state = {}; >>>> + JSONParsingState state; >>>> >>>> + memset(&state, 0, sizeof(state)); >>>> state.ap = ap; >>>> >>> >>> JSONParsingState state = { .ap = ap }; >>> >>> achieves the same. >> >> But the fundamental is, what problem does GCC have with the original? If >> there isn't a reasonable answer, then I'm inclined to think this warning >> mode is a waste of time. > > It falls under the "missing fields in initializer" warning. Arguably, > an empty initializer should be special cased, but it isn't. So the warning is for old style initializer lists? I disagree that it's a valid warning. First, {} is ambiguous as it can be an empty list of c99 initializers and an empty list of c89 initializers. But even for c89 initializers, it's very common practice to omit initializers and rely on the defaulted value. For instance, { 0 } is quite pervasive as an idiom. > > I agree that Jes's original patch is ugly, but the C99 initializer is > an improvement. Yes, I'm fine with your patch on it's own but I disagree with GCC's warnings here. Regards, Anthony Liguori > Paolo