PetscUnreachable#

Indicate to the compiler that a code-path is logically unreachable

Synopsis#

#include <petscmacros.h>
void PetscUnreachable(void)

Note#

Indicates to the compiler (usually via some built-in) that a particular code path is always unreachable. Behavior is undefined if this function is ever executed, the user can expect an unceremonious crash.

Example usage#

Useful in situations such as switches over enums where not all enumeration values are explicitly covered by the switch

  typedef enum {RED, GREEN, BLUE} Color;

  int foo(Color c)
  {
    // it is known to programmer (or checked previously) that c is either RED or GREEN
    // but compiler may not be able to deduce this and/or emit spurious warnings
    switch (c) {
      case RED:
        return bar();
      case GREEN:
        return baz();
      default:
        PetscUnreachable(); // program is ill-formed if executed
    }
  }

See Also#

SETERRABORT(), PETSCABORT(), PETSC_ATTRIBUTE_COLD, PetscAssume()

Level#

advanced

Location#

include/petscmacros.h


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