:orphan:
# PetscDefined
Determine whether a boolean macro is defined 
## Synopsis
```
#include <petscmacros.h>
int PetscDefined(def)
```
No Fortran Support


## Input Parameter

- ***def -*** PETSc-style preprocessor variable (without PETSC_ prepended!)



## Output Parameter

- ***<return-*** value> - Either integer literal 0 or 1





## Notes
`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_()`.

```none
#define FooDefined(d) PetscDefined_(PetscConcat(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.


## Example Usage
Suppose you would like to call either "foo()" or "bar()" depending on whether PETSC_USE_DEBUG
is defined then

```none
  #if PetscDefined(USE_DEBUG)
    foo();
  #else
    bar();
  #endif

  // or alternatively within normal code
  if (PetscDefined(USE_DEBUG)) {
    foo();
  } else {
    bar();
  }
```


is equivalent to

```none
  #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
```



## See Also
 `PetscHasAttribute()`, `PetscUnlikely()`, `PetscLikely()`, `PetscConcat()`,
`PetscExpandToNothing()`, `PetscCompl()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscmacros.h.html#PetscDefined">include/petscmacros.h</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/stag/tutorials/ex4.c.html">src/dm/impls/stag/tutorials/ex4.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex76.c.html">src/ksp/ksp/tutorials/ex76.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex79.c.html">src/ksp/ksp/tutorials/ex79.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex82.c.html">src/ksp/ksp/tutorials/ex82.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex5.c.html">src/snes/tutorials/ex5.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex55.c.html">src/snes/tutorials/ex55.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/include/petscmacros.h)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
