www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/25/20:01:25

Sender: nate AT cartsys DOT com
Message-ID: <35BA5AB5.C6AF6835@cartsys.com>
Date: Sat, 25 Jul 1998 15:22:45 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
MIME-Version: 1.0
To: Arthur <arfa AT clara DOT net>
CC: DJGPP Mailing List <djgpp AT delorie DOT com>
Subject: Re: Loading a BMP picture???
References: <00de01bdb684$5d2cd740$604d08c3 AT arthur>

Arthur wrote:
> 
> >int main()
> >{
> >    BITMAP *b;
> >    PALETTE p;
> >
> >    b = load_bitmap("backgr.bmp", p);
> >    if (!b)
> >    {
> 
> [snip]
> 
> Watch out. load_bitmap returns NULL if it can't load the file. NULL is not
> strictly the same as 0, so you should really check for if(b == NULL){...}
> instead of if(!b){...}

Unless I am gravely mistaken, the C standard says that NULL *is* the
same as 0.  Whenever 0 appears in a pointer context, the null pointer is
used, even if the null pointer on that architecture is not physically
zero.  In fact, NULL is defined as `(void *)0', which simply makes sure
it is always used as a pointer.  `#define NULL 0' is also legal.

Thus, `b == NULL' is equivalent to `!b', which tests to see if `b' is
nonzero.

This is probably a better topic for comp.lang.c; in fact, read its FAQ. 
It talks about this subject at some length.
-- 

Nate Eldredge
nate AT cartsys DOT com


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019