Why? When I try to use ((PetscObject)M)->comm in my function as follows, PetscErrorCode SetupDirectSolver(KSP *ksp, Mat M) { KSPCreate(((PetscObject)M)->comm,ksp); } I got error: dereferencing pointer to incomplete type