[petsc-dev] Why do we use void* instead of PetscObject in PETSc?

Jed Brown jed at jedbrown.org
Mon Mar 4 15:30:55 CST 2019

Dave May via petsc-dev <petsc-dev at mcs.anl.gov> writes:

> I think there would be a lot of merit (in the long run) if user contexts,
> such as given to KSPSetComputeOperators(), SNESSetJacobian() etc were
> changed to be of type PetscObject rather than void*.
> Some obvious benefits would be:
> [1] Type checking!

How is passing a void* to PetscObject/PetscContainer different from
passing it to SNES?  Also, would you have different types for every
callback or would you reuse?  If reusing, would the interface require
casting the function pointers to void(*)(void) instead of what is
currently type-safe for most function pointers?  This feels like less
rather than more type safety.

Agree on other points.

More information about the petsc-dev mailing list