PetscFunctionReturn — PETSc 3.25.0 documentation

Skip to main content
`Ctrl`+`K`

# PetscFunctionReturn

Last executable line of each PETSc function used for error handling. Replaces `return()`.

## Synopsis

    #include <petscsys.h>
    void PetscFunctionReturn(...)

Not Collective; No Fortran Support

## Notes

This routine is a macro, so while it does not “return” anything itself, it does return from the function in the literal sense.

Usually the return value is `PETSC_SUCCESS` (for example in any function returning `PetscErrorCode`), however it is possible to return any arbitrary type. The arguments of this macro are placed before the `return` statement as-is.

Any routine which returns via `PetscFunctionReturn()` must begin with a corresponding `PetscFunctionBegin`.

For routines which return `void` use `PetscFunctionReturnVoid()` instead.

## Example Usage

       PetscErrorCode foo(int *x)
       {
         PetscFunctionBegin; // don't forget the begin!
         *x = 10;
         PetscFunctionReturn(PETSC_SUCCESS);
       }

May return any arbitrary type:

      struct Foo
      {
        int x;
      };

      struct Foo make_foo(int value)
      {
        struct Foo f;

        PetscFunctionBegin;
        f.x = value;
        PetscFunctionReturn(f);
      }

## See Also

`PetscFunctionBegin`, `PetscFunctionBeginUser`, `PetscFunctionReturnVoid()`, `PetscStackPopNoCheck()`

## Level

beginner

## Location

include/petscerror.h

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