#include <petscmacros.h> int PetscDefined(def)
| def | - PETSc-style preprocessor variable (without PETSC_ prepended!) |
| <return | - value> - Either integer literal 0 or 1 |
PetscDefined() returns 1 if and only if "PETSC_ ## def" is defined (but empty) or defined to integer literal 1. In all other cases, PetscDefined() returns integer literal 0. Therefore this macro should not be used if its argument may be defined to a non-empty value other than 1.
The prefix "PETSC_" is automatically prepended to def. To avoid prepending "PETSC_", say to add custom checks in user code, one should use PetscDefined_().
#define FooDefined(d) PetscDefined_(PetscConcat(FOO_,d))
Our extra expansion via PetscDefined__take_second_expand() is needed with MSVC, which has a nonconforming implementation of variadic macros.
#if PetscDefined(USE_DEBUG)
foo();
#else
bar();
#endif
// or alternatively within normal code
if (PetscDefined(USE_DEBUG)) {
foo();
} else {
bar();
}
is equivalent to
#if defined(PETSC_USE_DEBUG)
# if MY_DETECT_EMPTY_MACRO(PETSC_USE_DEBUG) // assuming you have such a macro
foo();
# elif PETSC_USE_DEBUG == 1
foo();
# else
bar();
# endif
#else
bar();
#endif