0 or 0L for empty pointers?

Friedrich W. H. Kossebau Friedrich.W.H at kossebau.de
Tue Jun 20 19:10:24 BST 2006


Am Dienstag, 20. Juni 2006 20:02, schrieb Friedrich W. H. Kossebau:
> 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?
>
> IIRC it was something with sizeof(long)==sizeof(void*) not always true. Any
> experts?
> Perhaps this could be added to the KDE Library Code Policy then...

And when you send the mail you look even sharper. The pointer issue is 
mentioned at 
http://developer.kde.org/documentation/other/mistakes.html
which is referenced from the code policy.

"
Second of all you'll see null pointers marked with three types: 0, 0L and 
NULL. The argument against using NULL was that while C defines it as a 0 void 
pointer, C++ defines it to not be a 0 void pointer. All conforming C++ 
implementations will define NULL correctly so it's really not a problem. The 
argument for 0L was that it was handled correctly in variable argument 
functions, while 0 wasn't. Nowadays that's also an artifact.
 It's more a question of getting used to something. As far as the code in CVS 
goes you'll see 0 used more commonly than NULL. 
 "

As null pointers are often used as default values in the api docs it might 
make sense to standardise the usage there, no?

I personally preferred 0L, but meanwhile got used to 0 as well. So no wish 
from my side, besides a standard :)

Regards
Friedrich




More information about the kde-core-devel mailing list