PETSC_NULLPTR#

Standard way of indicating a null value or pointer No Fortran Support

Notes#

Equivalent to NULL in C source, and nullptr in C++ source. Note that for the purposes of interoperability between C and C++, setting a pointer to PETSC_NULLPTR in C++ is functonially equivalent to setting the same pointer to NULL in C. That is to say that the following expressions are equivalent:

  ptr == PETSC_NULLPTR
  ptr == NULL
  ptr == 0
  !ptr

  ptr = PETSC_NULLPTR
  ptr = NULL
  ptr = 0

and for completeness’ sake:

  PETSC_NULLPTR == NULL

Example Usage#

  // may be used in place of '\0' or other such terminators in the definition of char arrays
  const char *const MyEnumTypes[] = {
    "foo",
    "bar",
    PETSC_NULLPTR
  };

  // may be used to nullify objects
  PetscObject obj = PETSC_NULLPTR;

  // may be used in any function expecting NULL
  PetscInfo(PETSC_NULLPTR,"Lorem Ipsum Dolor");

Developer Notes#

PETSC_NULLPTR must be used in place of NULL in all C++ source files. Using NULL in source files compiled with a C++ compiler may lead to unexpected side-effects in function overload resolution and/or compiler warnings.

See Also#

PETSC_CONSTEXPR_14, PETSC_NODISCARD

Level#

beginner

Location#

include/petscmacros.h


Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages