(ref.doc)kanze 200194
Next fjh 260194
Prev: meyer 180194
Up: Usenet
Newsgroups: comp.std.c++
From: [email protected] (James Kanze)
Subject: Re: Plum&Saks Pointer Advice
Date: 20 Jan 1994 16:55:36 GMT
In article <[email protected]> [email protected] (Sharon
Barton) writes:
|> Can anyone tell me why Thomas Plum and Donald Saks recommend using
|> 0 to initialize pointers instead of NULL in their C++ Programming
|> Guidelines book? This isn't consistent with ANSI C. Isn't C++
|> based on ANSI C?
Here we go again:-(.
Historically, a number of early C++ compilers (well, at least one)
were really just front-ends for the C compiler. In addition, since
the commercial market was not worth the effort, the simple solution of
just enrobing the standard C header files in extern "C" { ... } was
adapted.
In C, NULL may be legally defined as '(void*)0', and some systems
actually do this. This works well in C, since a void* can be assigned
to any type of pointer. On the other hand, C++ does not allow an
implicit cast *from* void*, and this lead to the fact that you could
not assign NULL to a pointer (nor compare a pointer to NULL, nor...).
Today, there is a significant commercial market for C++; if the header
files for C++ define NULL as '(void*)0', then a complaint to your
vendor is in order. In fact, I know of no current implementation
where this is the case. So there is no *technical* reason not to use
NULL.
The question of style remains. I have many years of C experience, and
in all of the companies, the house style was to use NULL. I find that
information is missing when 0 is used; the type system is being
abused. In fact, until the last big discussion of this on the net, I
was convinced that without the obslete technical reason, only a hacker
would use 0. In that discussion, however, it became clear that
several people for whom I have great respect, and who are definitly
software engineers and not hackers (Paul Lucas and Pete Becker come to
mind) preferred 0 to NULL, even while recognizing that the technical
imperative was no longer valid. As a result, I am forced to consider
this a question of style. (But I still think my style is better:-).)
automatically generated by info2www version 1.2.2.8