PetscHasAttribute#

Determine whether a particular attribute is supported by the compiler

Synopsis#

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

Input Parameter#

  • name - The name of the attribute to test

Notes#

name should be identical to what you might pass to the attribute declaration itself – plain, unbroken text.

As PetscHasAttribute() is wrapper over the function-like macro __has_attribute(), the exact type and value returned is implementation defined. In practice however, it usually returns 1 if the attribute is supported and 0 if the attribute is not supported.

Example Usage#

Typical usage is using the preprocessor

  #if PetscHasAttribute(always_inline)
  #  define MY_ALWAYS_INLINE __attribute__((always_inline))
  #else
  #  define MY_ALWAYS_INLINE
  #endif

  void foo(void) MY_ALWAYS_INLINE;

but it can also be used in regular code

  if (PetscHasAttribute(some_attribute)) {
    foo();
  } else {
    bar();
  }

See Also#

PetscHasBuiltin(), PetscDefined(), PetscLikely(), PetscUnlikely(), PETSC_ATTRIBUTE_FORMAT, PETSC_ATTRIBUTE_MAY_ALIAS

Level#

intermediate

Location#

include/petscmacros.h


Edit on GitLab

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