Re: NULL: Is it guaranteed to evaluate 'not true'

From: John Winters (newstmp_at_linuxemporium.co.uk)
Date: 10/02/03

  • Next message: Peter T. Breuer: "Re: Can "pppd" bind to a pty with "telnet" session over ethernet?"
    Date: Thu, 2 Oct 2003 17:27:01 +0000 (UTC)
    
    

    In article <Xns94018E057A0BDCopyrightMarkOdell@130.133.1.4>,
    Mark A. Odell <nospam@embeddedfw.com> wrote:
    >Is NULL guaranteed to evaluate 'not true', e.g. is it completely safe and
    >portable to write:
    >
    >char *pFoo = malloc(1024);
    >if (pFoo)
    >{
    > /* use pFoo
    > */
    > free(pFoo);
    >}
    >
    >Or must I check against NULL explicitly as in:
    >
    >if (pFoo != NULL) ...

    Yes, what you want to do is safe, but it's important to differentiate
    between NULL (a pre-processor macro) and a null pointer. I think
    the question which you meant to ask was "Is a null pointer guaranteed
    to evaluate 'not true'?", to which the answer is yes.

    Some (including me) would argue that it's better style to include the
    explicit comparison with NULL, because it makes the code more
    self-documenting.

    HTH
    John

    -- 
    The Linux Emporium - the source for Linux in the UK
    See http://www.linuxemporium.co.uk/
    We had a woodhenge here once but it rotted.
    

  • Next message: Peter T. Breuer: "Re: Can "pppd" bind to a pty with "telnet" session over ethernet?"

    Relevant Pages

    • Re: NBC: What Are You Reading?
      ... Jack Kerouac's ON THE ROAD. ... More explicit than the official version ... with actual names instead of pseudonyms. ... Mark L. Falconer-film and video links at ...
      (rec.music.artists.springsteen)
    • Re: St Matthews Academy
      ... You're making lots of really stupid assumptions then phrasing them as questions. ... You've even stuck a question mark on the sentance above. ... Yes I stuck a question mark in the sentence above because I was questioning why you refuse to explain yourself. ... If you can't be explicit or explain perhaps you should consider your own reasoning before replying further. ...
      (uk.rec.cycling)
    • Re: Mark project complete?
      ... Jones" wrote: ... Is there any way to mark them as completed? ... Uncheck the due date and optionally add a "Done" label to the project name. ... There's no explicit way to do it. ...
      (microsoft.public.mac.office.entourage)
    • COPYING FILES TO CD-RW
      ... When i click on properties it has a check mark on archive. ... When I right click to send that file to cd-rw a bubble ... please be explicit. ... I'm no computer nerd. ...
      (microsoft.public.word.newusers)