0

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 and ops ?

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 */    
...
ocramz
  • 816
  • 6
  • 18
  • 2
    Regarding the first point, [this translation phase reference](http://en.cppreference.com/w/c/language/translation_phases) might be helpful, especially phase 4. I also recommend you run the code though a pre-processor, and look at how the pre-processed code looks before the compiler "proper" gets it. – Some programmer dude May 14 '15 at 17:50
  • I have already built this library, perhaps I can find the preprocessed source somewhere or is it usually removed after make? Otherwise, is there e.g. a set of cpp flags for emitting just this? – ocramz May 14 '15 at 17:59
  • Usually there is no separate pre-processor step, but you can either invoke the pre-processor directly (`cpp` in POSIX (like Linux or OSX) environment), or use e.g. `gcc -E` (with normal flags) to ask the GCC compiler to stop after pre-processing your source. There should be options to produce pre-processed code in Visual Studio too, and probably in other IDEs as well. – Some programmer dude May 14 '15 at 18:09

0 Answers0