View Single Post

   
  #2 (permalink)  
Old 01-17-2008, 07:06 AM
Mark A. Odell
 
Posts: n/a
Default Re: NULL: Is it guaranteed to evaluate 'not true'

"Mark A. Odell" <nospam@embeddedfw.com> wrote in
news:Xns94018E057A0BDCopyrightMarkOdell@130.133.1. 4:

I meant to post this in comp.lang.c. I ended up doing so and I'll answer
my post here with the answers received there.

> Is NULL guaranteed to evaluate 'not true', e.g. is it completely safe
> and portable to write:


Yes.

> char *pFoo = malloc(1024);
> if (pFoo)
> {


This is safe.

> /* use pFoo
> */
> free(pFoo);
> }
>
> Or must I check against NULL explicitly as in:
>
> if (pFoo != NULL) ...


No, they are equivalent.

--
- Mark ->
--
Reply With Quote