Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
how to use cppcheck in c::b
rcoll:
--- Quote from: oBFusCATed on February 19, 2010, 02:31:13 pm ---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
--- End quote ---
Excellant! I trust the GCC definitions, and so that means that now NULL is a synonym for a constant 0. But I still prefer to use NULL when assigning to pointers, if only for the fact that the definition of NULL might change in the future (as it already has), and so my code would stay compatible with future compilers.
Ringo
killerbot:
the argument NULL is easier to replace by the new keyword sounds good to me.
But people like Dewhurst, Meyers convinced me to use 0. So my 'NULL' days are over ;-)
But if you really prefer to use NULL, just do it, but I wouldn't go into changing source that already uses 0, instead of the macro, since that is a little bit one step backward.
blueshake:
--- Quote ---CppCheck.h|31|memleak : possible error : Memory leak: CppCheck::m_CppCheckLog|
CppCheck.h|32|memleak : possible error : Memory leak: CppCheck::m_ListLog|
--- End quote ---
Did we miss the important thing??It seems some memory leak here. :D
rcoll:
--- Quote from: blueshake on February 20, 2010, 05:32:04 am ---
--- Quote ---CppCheck.h|31|memleak : possible error : Memory leak: CppCheck::m_CppCheckLog|
CppCheck.h|32|memleak : possible error : Memory leak: CppCheck::m_ListLog|
--- End quote ---
Did we miss the important thing??It seems some memory leak here. :D
--- End quote ---
Cppcheck reported that "possible memory leak" because it saw a constant value (see our discussion about NULL) being assigned to pointers, without a preceeding "delete" or "free" on those pointers. Therefore, Cppcheck thinks there is a possibility of "orphan" data blocks in memory.
However, the piece of code in question appears to be a constructor, meaning that there is no memory block assigned to those pointers; the assignment is merely an initializer.
Ringo
oBFusCATed:
Which brings us here: http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6
--- Quote ---Initialization lists. In fact, constructors should initialize as a rule all member objects in the initialization list. One exception is discussed further down.
--- End quote ---
Navigation
[0] Message Index
[*] Previous page
Go to full version