From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5277 invoked by alias); 11 Dec 2012 10:22:09 -0000 Received: (qmail 5260 invoked by uid 22791); 11 Dec 2012 10:22:07 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Dec 2012 10:21:58 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBBALtgw002125 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Dec 2012 05:21:55 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBBALrKq013834; Tue, 11 Dec 2012 05:21:53 -0500 Message-ID: <50C7093F.5000600@redhat.com> Date: Tue, 11 Dec 2012 10:22:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Jan Kratochvil CC: Joel Brobecker , gdb-patches@sourceware.org, Matt Rice Subject: Re: [doc patch] coding style: 0 vs. NULL + [patch] Code cleanup: skip.c References: <20121210184220.GA29321@host2.jankratochvil.net> <20121211015343.GM31477@adacore.com> <20121211060641.GA7775@host2.jankratochvil.net> In-Reply-To: <20121211060641.GA7775@host2.jankratochvil.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-12/txt/msg00312.txt.bz2 On 12/11/2012 06:06 AM, Jan Kratochvil wrote: > On Tue, 11 Dec 2012 02:53:43 +0100, Joel Brobecker wrote: >>> But GDB (IMO fortunately) already uses everywhere properly NULL vs. 0. >> [...] >>> I have added a new rule for the coding style for it. >> >> So, just to be certain, this also includes testing for NULL, right? > > I did not think about this case. > > >> Code like... >> >> first = strstr (big, small); >> if (first) >> >> ... should be written instead: >> >> if (first != NULL) > > I find '(first)' OK myself but IIRC Pedro recently in some mail wrote he likes > more an explicit NULL comparison there. Although I cannot find his mail now > so I hope I do not put these words in Pedro's mouth. Yes, indeed I mentioned it recently somewhere. Personally, I find implicit boolean conversions make the code harder to grok, so I prefer the latter. > not great if (!first) Indeed. That's about the same level of badness as '!strcmp(a, b)' to me. > OK if (first) I look at this the same as '(!first)' - it's the same implicit boolean conversion, so I look at it as a matter of consistency to write 'if (first == NULL)' if one writes 'if (first != NULL)'. -- Pedro Alves