0 or 0L for empty pointers?
Lubos Lunak
l.lunak at suse.cz
Wed Jun 21 17:28:22 BST 2006
On Tuesday 20 June 2006 20:02, Friedrich W. H. Kossebau wrote:
> Hello,
>
> looking through some apis from trunk I see a lot of 0L for empty pointers.
> I do not remember where I read it, but shouldn't it be never 0L and always
> 0 for pointers?
In fact you should be using NULL and not 0 or 0L, because with some compilers
like gcc NULL is a real null pointer and allows the compiler to catch some
stupid mistakes. 0 and 0L are integers that just happen to be converted to a
null pointer if the compiler sees no other way (besides, I can't resists
mentioning it, using 0 instead of NULL is about as C++-ish as using 0,1,2
instead of an enum).
If you want to know what Stroustrup himself thinks about it just read the doc
mentioned in the of the comments at http://www.kdedevelopers.org/node/1636
(short summary: 0 or 0L as null pointer suck, NULL sucks too but less, next
C++ revision is likely going to have nullptr as null pointer).
> IIRC it was something with sizeof(long)==sizeof(void*) not always true. Any
> experts?
If you really want a pointer, like with variadic functions, you have to
explicitly cast it to a pointer anyway.
> Perhaps this could be added to the KDE Library Code Policy then...
>
> Regards
> Friedrich
--
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o. e-mail: l.lunak at suse.cz , l.lunak at kde.org
Drahobejlova 27 tel: +420 2 9654 2373
190 00 Praha 9 fax: +420 2 9654 2374
Czech Republic http://www.suse.cz/
More information about the kde-core-devel
mailing list