This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Fwd: Re: GCC headers and DJGPP port (OT)]




-------- Original Message --------
From: Anjul <anjul@cyberspace.org>
Subject: Re: GCC headers and DJGPP port (OT)
To: Linus Torvalds <torvalds@transmeta.com>

I personally hate using NULL anywhere in C/C++ code.

0 has special status in C (and also I presume C++). I don't have K&R
with me
now, but if you search the index (for NULL (?)), you will find a
paragraph
that goes like (can send you the exact pp. later if you wish):

""The integer 0 can be compared or assigned to any pointer type and in
such
an operation it is implicitly converted into a pointer value that is
guaranteed to not be the address of any valid object."" [ note that this
is
valid only for the integer constant 0 and not for any other integer
constant
]

Therefore, (void *)0 is quite unnecessary. 0 would serve the same
purpose.
Perhaps, one use of (void *)0 would be to restrict its comparison or
assignment to int, char, long, ... types. I don't see this advantage as
significant or important. To try to stop programmers from writing "int
i=NULL;" is in the direction of trying to stop car-owners from putting
sand
in their gas-tanks.

Linus Torvalds wrote:

> In article <200007222029.QAA29095@disaster.jaj.com>,
> Phil Edwards  <pedwards@disaster.jaj.com> wrote:
> >
> >Having __null magically only match pointer types is an extremely froody
> >solution, and I'm glad that g++ went that route.
>
> Off-topic: why is it exactly that C++ doesn't like the "((void *)0)"
> thing, which as far as I can tell has all the same advantages? Was it
> purely a "stupid standard" issue, or is there some actual real deeper
> reason for it?
>
> That was one of my pet peeves about C++: I always considered the
> historical "#define NULL 0" to be complete braindamage due to lack of
> even the simplest kind of type-checking (and matching to a pointer type
> is just one small portion of that type-checking - getting sane and
> appropriate warnings is quite important).
>
> And C++ made the ANSI-C-approved "((void *)0)" define illegal for some
> reason that I still haven't quite grasped. Gcc used to have the "don't
> complain" extension for some time, and now we've moved to "__null". What
> were the issues, just out of morbid curiosity?
>
> Or am I better off not knowing?
>
>                 Linus

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]