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

From: Kari Hurtta
Date: Thu Jul 08 2004 - 07:40:54 EST


-- 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
-
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/