[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: NULL vs. 0 (was Re: PATCH: flicker in startup identification)
From:       jan () etpmod ! phys ! tue ! nl
Date:       2001-05-18 15:27:11
[Download RAW message or body]

Harri Porten wrote:

> > On Friday 18 May 2001 14:44, Lubos Lunak wrote:
> >
> > >  Hmm. Such a long patch for a one-line change. Is there any serious reason
> > > why you want to replace all the NULL's with 0's ? It's the same.
> >
> > Not quite, according to Stroustrup use of NULL is discouraged, 0 is
> > preferred. I think it's because NULL is typed while '0' is "more flexible" or
> > something like that. I don't have my copy of TC++PL 3rd at hand.
>

OK, here it comes: a shameless copy of section 5.1.1, 'Zero' of The Book:

"
Zero(0) is an int. Because of standard conversions, 0 can be used as a constant of
any integral, floating point, pointer, or pointer-to-member type. The type of zero
will be determined by context. Zero will typically (but not necessarily) be
represented by the bit pattern 'allzeros' of the appropriate size.

No object is allocated with the address 0. Consequently, 0 acts as a pointer
literal, indicating that the pointer doesn't refer to an object.

In C, it has been popular to define a macro NULL to represent the zero pointer.
Because C++'s tighter type checking, the use of plain 0, rather than any suggested
NULL macro, leads to fewer problems. If you feel you must define NULL, use

    const int NULL=0;

The const qualifier prevents accidental redifinition of NULL and ensures that
NULL can be used where a constant is expected.
"

So, if you want to conform to The Master's thoughts on this, 0 should be used,
even though the standard has no opinion about it.

Greetings, Jan.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic