[vtk-developers] C++ NULL definition (was: Request for a gentler tone in commit message verbiage...)

Bill Lorensen bill.lorensen at gmail.com
Thu Apr 30 10:29:45 EDT 2015


In ITK we define ITK_NULLPTR which is nullptr for c++11 and NULL for
earlier c++'s.
we use
#if __cplusplus >= 201103L

to detect c++11. All NULL's in ITK have been changed to ITK_NULLPTR.

Here is the code snippet we use:
#if __cplusplus >= 201103L
// In c++11 the override keyword allows you to explicity define that a function
// is intended to override the base-class version.  This makes the code more
// managable and fixes a set of common hard-to-find bugs.
#define ITK_OVERRIDE override
// In c++11 there is an explicit nullptr type that introduces a new keyword to
// serve as a distinguished null pointer constant: nullptr. It is of type
// nullptr_t, which is implicitly convertible and comparable to any pointer type
// or pointer-to-member type. It is not implicitly convertible or comparable to
// integral types, except for bool.
#define ITK_NULLPTR  nullptr
// In C++11 the throw-list specification has been deprecated,
// replaces with the noexcept specifier. Using this function
// specification adds the run-time check that the method does not
// throw, if it does throw then std::terminate will be called.
// Use cautiously.
#define ITK_NOEXCEPT noexcept
#else
#define ITK_OVERRIDE
#define ITK_NULLPTR  NULL
#define ITK_NOEXCEPT throw()
#endif


On Thu, Apr 30, 2015 at 10:26 AM, Brad King <brad.king at kitware.com> wrote:
> On 04/30/2015 10:20 AM, Robert Maynard wrote:
>> Actually the definition of NULL is left up to each compiler. The C++11
>> draft states "The macro NULL < snip> is an implementation-defined C++
>> null pointer constant"
>
> C++98 18.1/4 says it is implementation defined but has a footnote
> that does not leave much room:
>
>  180) Possible definitions include 0 and 0L, but not (void*)0.
>
> The reason plain C's "((void*)0)" does not work in C++ is because
> C++ is strict about pointer conversions where C is tolerant.
>
> -Brad
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Search the list archives at: http://markmail.org/search/?q=vtk-developers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtk-developers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtk-developers mailing list