1  #include <stdlib.h>
       2  #include <stdio.h>
       3  
       4  #include <ISO_Fortran_binding.h>
       5  #include "dump-descriptors.h"
       6  
       7  extern void ctest (int n);
       8  extern void ftest (CFI_cdesc_t *a, int n);
       9  
      10  #define BUFSIZE 512
      11  static char adata[BUFSIZE];
      12  
      13  void
      14  ctest (int n)
      15  {
      16    CFI_CDESC_T(0) adesc;
      17    CFI_cdesc_t *a = (CFI_cdesc_t *) &adesc;
      18  
      19    /* Use a fixed-size static buffer instead of allocating one dynamically.  */
      20    if (n > BUFSIZE)
      21      abort ();
      22  
      23    /* Fill in adesc.  */
      24    check_CFI_status ("CFI_establish",
      25  		    CFI_establish (a, adata, CFI_attribute_other,
      26  				   CFI_type_char, n, 0, NULL));
      27  
      28    /* Sanity checking to make sure the descriptor has been initialized
      29       properly.  */
      30    dump_CFI_cdesc_t (a);
      31    if (a->version != CFI_VERSION)
      32      abort ();
      33    if (a->rank != 0)
      34      abort ();
      35    if (a->attribute != CFI_attribute_other)
      36      abort ();
      37    if (a->elem_len != n)
      38      abort ();
      39    
      40    /* Call back into Fortran.  */
      41    ftest (a, n);
      42  }