Mail Archives: djgpp/1998/07/25/20:01:25
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 -