title: How to allocate an array inside fortran routine "called" from C
body: <p>I think title says what I need. I know we can use "asd" function to do this, but for some reasons I need to do the allocation in Fortran (i.e. in subroutine "asd_"). Here is the C code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void asd(float **c) {
    *c = (float *) malloc (2*sizeof(float));
    **c =123;
    *(*c+1)=1234;
  }
  
  void asd_(float **c);
  
  main () {
    float *c;
    asd_(&amp;c);
  // asd(&amp;c); would do the job perfectly
    printf("%f %f \n",c[0],c[1]);
    return 0;
  }
  </code></pre>
  
  <p>And here is the Fortran code:</p>
  
  <pre><code>  subroutine asd(c)
  
    implicit none
  
    real, pointer, allocatable ::c(:)
  
    print *, associated(c)
    if(.not. associated(c))  allocate(c(2))
  
    end subroutine 
  </code></pre>
  
  <p>This randomly gives segmentation fault. Any help would be appreciated.</p>