Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

how to use cppcheck in c::b

<< < (2/3) > >>

killerbot:
this will change within 2 weeks.
I have committed a patch to ccpcheck team, which got applied, and this will allow to specify the files to check in an input file. At that moment I will also update our plug-in and we will only support this new way.

With respect to the X =NULL;  ; my very strong personal feeling is not to use NULL, but use 0.
And in the future we will have a special null_ptr keyword (C++Ox) and then all discussions are over ;-)

rcoll:

--- Quote from: killerbot on February 19, 2010, 12:29:45 pm ---With respect to the X =NULL;  ; my very strong personal feeling is not to use NULL, but use 0.
And in the future we will have a special null_ptr keyword (C++Ox) and then all discussions are over ;-)

--- End quote ---

Sorry, I know this is not the right place to ask this, but my curiosity overwhelms my common sense sometimes.

Why against NULL so much?  The C++ standard (such that it is) guarantees the keyword NULL to be compatible with all pointer types, but (at my last reading) the constant 0 was NOT guaranteed to be converted to a null pointer (unlike the older linear C, where constant 0 WAS guaranteed to be a null pointer).  (I could be very much out of date here regarding the standards).

Ringo

oBFusCATed:

--- Quote from: killerbot on February 19, 2010, 12:29:45 pm ---With respect to the X =NULL;  ; my very strong personal feeling is not to use NULL, but use 0.
And in the future we will have a special null_ptr keyword (C++Ox) and then all discussions are over ;-)

--- End quote ---

In my opinion using NULL (or a custom nullptr version) is better than 0, because when the C++1x is supported we can do Replace all NULL -> nullptr and we are done, but with 0 you can't do this.

BTW, NULL is #define NULL 0L most of the time (not 100% sure)

rcoll:

--- Quote from: oBFusCATed on February 19, 2010, 01:56:01 pm ---BTW, NULL is #define NULL 0L most of the time (not 100% sure)

--- End quote ---

In the (rather old) copy of the standard I have, NULL is defined as a macro

#define   NULL   ((void *) 0)

where the constant 0 is type-cast to a void*, ensuring the  created value would represent an invalid address.  Obviously, on some machines (an old CDC comes to mind), the "actual" address of 0 was valid (it was a machine register).

Ringo

oBFusCATed:
Extract from some of the headers in:

VC2005:

--- Code: ---/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif

--- End code ---

GCC 4.4.3

--- Code: ---#if defined (_STDDEF_H) || defined (__need_NULL)
#undef NULL             /* in case <stdio.h> has defined it. */
#ifdef __GNUG__
#define NULL __null
#else   /* G++ */
#ifndef __cplusplus
#define NULL ((void *)0)
#else   /* C++ */
#define NULL 0
#endif  /* C++ */
#endif  /* G++ */
#endif  /* NULL not defined and <stddef.h> or need NULL.  */
#undef  __need_NULL


--- End code ---

BTW: for everyone interested in nullptr -> http://blogs.msdn.com/vcblog/archive/2009/10/27/channel-9-video-stephan-t-lavavej-everything-you-ever-wanted-to-know-about-nullptr.aspx

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version