Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: guidelines for pointer check Date: Thu, 29 Dec 2016 13:39:25 -0800 Organization: None to speak of Lines: 49 Message-ID: References: <4598b1a6-e647-4327-85d8-23f83198d0c6@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="e52b6227186de46e02b6ceefa726c58c"; logging-data="22731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189XMc91aqod7/rnswTaiHB" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:70SYV2K/eSImBibMrkKt6EWzlNM= sha1:AwL8C5nkt1y+PpAsHGZWIoc93Bs= Xref: csiph.com comp.lang.c:100501 Thiago Adams writes: > Do you have some style guideline for pointer checking? > > This is a kind of poll: > > > //Style 1 > if (pVariable) { /*...*/ } > > //Style 2 > if (pVariable != NULL) { /*...*/ } > > //Style 3 > if (pVariable != 0) { /*...*/ } > > Do you dislike one of them? > Do you use only one of them? > Do you use more than one? > Other? I prefer `if (pVariable != NULL)`. As Stefan Ram points out, NULL requires #including a standard header, but in a program of any complexity one of the several standard headers that define NULL will almost certainly already be #included -- and if not, adding `#include Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"