OMNI_NULL_PTR
MACRO

OMNI_NULL_PTR - The NULL value used throughout the library.

SYNOPSIS top

This is a helper macro used throughout the library to signify a NULL value used.

DESCRIPTION top

As the NULL macro is implementation defined and not all compilers will support the nullptr keyword, the default for null pointer values is to zeroize them, that is, the preferred way to initialize pointer types to the null value is to set them to the 0 address over setting to NULL or nullptr.

Example:
int* val = 0;       <- preferred way
int* val = NULL;    <- OK, but NULL could be anything, so not really 'safe'
int* val = nullptr; <- OK and expresses intent better, but not all compilers support this
We don't want to overuse macro's through the library, but in this scenario, it's also preferable to avoid being able to do something like this:
static const int nullptr = 0;
int* val = &nullptr;
'&nullptr' is not allowed in C++11 and additional checks would need to be in place to avoid this in C++11 compilers and not in previous editions; as well int* val = nullptr could have an implicit cast since you are referencing a named variable (nullptr ), this isn't the case in C++11 with the nullptr keyword.

To avoid all of this, this macro gives the user the option to choose (or define) their null pointer value. Defining OMNI_USE_NULLPTR sets the C++11 nullptr keyword while OMNI_USE_NULL will use the implementation defined NULL macro, and if nothing is defined to specify which null value to use, the default is to use the 0 address. While the macro name OMNI_NULL is more verbose than 0/NULL/nullptr it does express the intent better than just plain 0 (which on a cursory glance of the code, one might think 0 is an int instead of a null value).

CONSIDERATIONS top

The NULL macro is implementation defined and not all compilers will support the nullptr keyword.

PLATFORM SPECIFIC top

No platform specific notes.

NOTES top

None.