petsc-master 2020-10-23
Report Typos and Errors

PetscDefined

determine whether a boolean macro is defined

Notes

The prefix "PETSC_" is added to the argument.

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, it evaluates true if PETSC_USE_DEBUG is defined (merely defined or defined to 1), and false if PETSC_USE_DEBUG is undefined. This macro should not be used if its argument may be defined to a non-empty value other than 1.

To avoid prepending "PETSC_", say to add custom checks in user code, one can use e.g.

 #define FooDefined(d) PetscDefined_(FOO_ ## d)

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