In PETSc, a number of common-use structures such as Vec, Mat, IS, etc. are defined similarly, as in the 4 snippets below. Questions:
- when and how is PETSCHEADER expanded? I am writing the foreign interface from another language, and was wondering whether I have to wrap the macro in a function or whatnot
- What's the scope of
hdr
andops
?
Thanks in advance
petscvec.h
typedef struct _p_Vec* Vec;
vecimpl.h
struct _p_Vec {
PETSCHEADER(struct _VecOps);
PetscLayout map;
void *data; /* implementation-specific data */
...
petscimpl.h
#define PETSCHEADER(ObjectOps) \
_p_PetscObject hdr; \
ObjectOps *ops
vecimpl.h
typedef struct _VecOps *VecOps;
struct _VecOps {
PetscErrorCode (*duplicate)(Vec,Vec*); /* get single vector */
PetscErrorCode (*duplicatevecs)(Vec,PetscInt,Vec**); /* get array of vectors */
...