PetscHasBuiltin#

Determine whether a particular builtin method is supported by the compiler

Synopsis#

#include <petscmacros.h>
int PetscHasBuiltin(name)

Input Parameter#

  • name - the name of the builtin routine

Notes#

Evaluates to 1 if the builtin is supported and 0 otherwise. Note the term “evaluates” (vs “expands”) is deliberate; even though PetscHasBuiltin() is a macro the underlying detector is itself is a compiler extension with implementation-defined return type and semantics. Some compilers implement it as a macro, others as a compiler function. In practice however, all supporting compilers return an integer boolean as described.

Example Usage#

Typical usage is in preprocessor directives

  #if PetscHasBuiltin(__builtin_trap)
  __builtin_trap();
  #else
  abort();
  #endif

But it may also be used in regular code

  if (PetscHasBuiltin(__builtin_alloca)) {
    foo();
  } else {
    bar();
  }

Developer Note#

Clang’s __has_builtin() prior to Clang 10 did not properly handle non-function builtins such as __builtin_types_compatible_p() which take types or other non-functiony things as arguments. The correct way to detect these then is to use __is_identifier() (also a Clang extension). GCC has always worked as expected. See https://stackoverflow.com/a/45043153

See Also#

PetscHasAttribute(), PetscAssume()

Level#

intermediate

Location#

include/petscmacros.h


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