[Dcmlib] Pointeur NULL vs pointeur 0
jean-michel.rouet at philips.com
jean-michel.rouet at philips.com
Mon Feb 7 09:57:16 CET 2005
Bonjour,
je suis d'accord que ce n'est pas normal d'avoir parfois NULL parfois 0.
Néanmoins je trouve le "Coding Style" de gdcm un peu rude.
A condition que NULL soit défini correctement en fonction du langage et du
compilo,
il est recommandé de l'utiliser.
Pour info, je vous mets un extrait de la ml tuxcppprogramminh.
JM
On Sonntag, 22. Februar 2004 16:12, Peter Poulsen wrote:
> I have read that we should use 0 over NULL when setting a pointer to
> "nothing".
>
> Does anybody know why?
In C NULL is often defined as '(void *)0' and this is incorrect in C++
because there the type of NULL must be an integer type. Otherwise, you
could not assign NULL to a pointer. This is because in C++ there is no
automatic conversion from 'void *' to any other type.
So several people and style guides recommend not using NULL in C++. But
nowadays most of the heaeder files are prepared for using C++ and they
define NULL correctly (as 0, or with gcc as __null). Using NULL with gcc
is perfectly OK.
> To me it seems better to use NULL as it indicates
> in the code that this is a pointer being set to nothing, and not an
> interger being assigned the value 0.
ACK! And thats the reason why I still use NULL and also recommend in doing
so.
> I am aware that in most compilers NULL is just a macro for 0.
... if you are using C++ (i.e. '__cplusplus' is defined). For C it will
most certainly still be '(void *)0'. Have a look at stddef.h.
Torsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.creatis.insa-lyon.fr/pipermail/dcmlib/attachments/20050207/b59ec10b/attachment.html>
More information about the Dcmlib
mailing list