petsc-master 2020-08-05
Report Typos and Errors

PetscDefined

determine whether a boolean macro is defined

Notes

Typical usage is within normal code,

  if (PetscDefined(USE_DEBUG)) { ... }

but can also be used in the preprocessor,

  #if PetscDefined(USE_DEBUG)
    ...
  #else

Either way evaluates true if PETSC_USE_DEBUG is defined (merely defined or defined to 1) or undefined. This macro should not be used if its argument may be defined to a non-empty value other than 1.

Developer Notes

Getting something that works in C and CPP for an arg that may or may not be defined is tricky. Here, if we have "#define PETSC_HAVE_BOOGER 1" we match on the placeholder define, insert the "0," for arg1 and generate the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one). When PETSC_HAVE_BOOGER is not defined, we generate a (... 1, 0) pair, and when the last step cherry picks the 2nd arg, we get a zero.

Our extra expansion via PetscDefined__take_second_expand() is needed with MSVC, which has a nonconforming implementation of variadic macros.

Level

developer

Location

include/petscsys.h

Examples

src/ksp/ksp/tutorials/ex79.c.html
src/snes/tutorials/ex5.c.html

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