New authorization library moved to kdereview
Michael Pyne
mpyne at kde.org
Sat Jul 25 20:06:42 BST 2009
On Thursday 23 July 2009 01:18:58 Martin T. Sandsmark wrote:
> On Thursday 23. July 2009 22:36:12 Albert Astals Cid wrote:
> > My bad, i was informed on IRC that NULL vs 0 is not a "done" thing so
> > it's left to coder to decide.
>
> In Amarok 0 is preferred, fwiw:
>
> 0 vs NULL
> ---------
> The use of 0 to express a null pointer is preferred over the use of NULL.
> 0 is not a magic value, it's the defined value of the null pointer in C++.
> NULL, on the other hand, is a preprocessor directive (#define) and not
> only is it more typing than '0' but preprocessor directives are less
> elegant.
And as yet another counterpoint, you must be *extremely* careful using 0 with
a library's C API.
For instance, glib and derived code in general seems to be a big fan of C
functions taking a variable number of arguments, terminated by a sentinel
value.
When I was using gstreamer in JuK, there was once code that used a gst varargs
function, properly terminated by the null pointer, 0.
But it turns out that since C++ didn't know that the 0 was meant to be a
pointer and not an integer, this caused crashes on 64-bit systems (C++ used
(int)0 instead of (void*)0).
But you can't simply #define NULL ((void*)0) in C++ because the conversion
from void* to T* (for any given type T) is not allowed.
For this reason gcc defines a specific null pointer type (__null), which is
what NULL is defined to in C++ code. Of course, then they decided to make it
exactly equivalent to 0 (it even acts as an int in overload resolution... :( )
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35669
In addition, the next revision to C++ will standardize the specific null
pointer, called nullptr (and thence force gcc to restore their old behavior
for __null I would imagine, or at least give us a working null pointer).
So the conclusion? Using NULL will probably get you what you want both now
(warning converting to int with gcc < 4.2) and in the future (once it's
defined to nullptr in C++). Also in the future with the upcoming C++ standard
it will be easier to grep for NULL in a search/replace than 0 will be.
Regards,
- Michael Pyne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090725/abeb3e90/attachment.sig>
More information about the kde-core-devel
mailing list