Re: [OT] NULL versus 0 (Re: [PATCH] Use NULL instead of integer 0 insecurity/selinux/)

From: Kari Hurtta
Date: Thu Jul 08 2004 - 08:01:10 EST


-- Start of PGP signed section.
> That's all OK, fine and correct, but
> #define NULL 0
> would work for both, C and C++ as far as I can see.
> Am I missing some special case?

As far I know it does not work on C when it is
used as argument of function and function
have not prototype or function's prototype have ...

In that case compiler do not know that pointer
is required instead of integer.

However this is just "as far I know", now I have not
in hand reference (or I did not found good quotation.)

/ Kari Hurtta

>
> Quoting Kari Hurtta <hurtta+zz1@xxxxxxxxxxxxxxx>:
> > -- Start of PGP signed section.
> > > Quoting Martin Zwickel <martin.zwickel@xxxxxxxxxxxxxx>:
> > > > include/linux/stddef.h:
> > > >
> > > > #undef NULL
> > > > #if defined(__cplusplus)
> > > > #define NULL 0
> > > > #else
> > > > #define NULL ((void *)0)
> > > > #endif
> > >
> > > Yes, I never understood the reason for this ugly
> > > #if defined(__cplusplus) here.
> > > It works, but is IMHO unneccessary.
> > >
> >
> > (This is is off topic, because kernel is not C++, but C).
> >
> > Some quotations from Bjarne Stroustrup: The C++ Programming Language
> > (Third Edition),
> >
> > p. 843: Note that a pointer to function or a pointer to member
> > cannot be implicity converted to a void *.
> >
> > p. 844: A constant expression (§C.5) that evaluates to 0 can
> > be implicitly converted to any pointer or pointer
> > to member type (§5.1.1.).
> >
> >
> > p. 88: In C, it has been popular to define a macro NULL to
> > represent the zero pointer. Because of 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;
> >
> > (typos mine.)
> >
> > / Kari Hurtta
> >
> >
>
> --
> Regards Michael Buesch [ http://www.tuxsoft.de.vu ]
>
>
-- End of PGP signed section, PGP failed!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/