title: Calling C from Fortran: ``void*`` return value
body: <h1>How to call a <code>void *function(...)</code> from Fortran?</h1>
  
  <p>I am currently trying to call a few C functions from Fortran. I have done so before, but I have called only my own functions. For example, to call:</p>
  
  <pre><code>void add(int *csum, int *ca, int *cb) { *csum = *ca + *cb; }
  </code></pre>
  
  <p>from Fortran, I have used:</p>
  
  <pre><code>INTEGER :: fsum, fa, fb
  CALL add(fsum, fa, fb)
  </code></pre>
  
  <p><strong>This works fine.</strong> Now I have a couple of functions roughly like:</p>
  
  <pre><code>void *create_obj(void);
  void use_obj(void *obj);
  void free_obj(void *obj);
  </code></pre>
  
  <p>or even:</p>
  
  <pre><code>struct private_struct; /* defined somewhere else */
  struct private_struct *create_p(void);
  void use_p(struct private_struct *p);
  void free_f(struct private_struct *p);
  </code></pre>
  
  <p>where the struct is private, i.e., I have no knowledge of its members.</p>
  
  <p><em><strong>Question:</em> How can I get the return values into Fortran?</strong> I do not really need to access them, but I must store them somehow during their <code>create</code>...<code>use</code>...<code>destroy</code> lifecycle.</p>