1  #include <stdlib.h>
       2  #include <stdio.h>
       3  
       4  #include <ISO_Fortran_binding.h>
       5  #include "dump-descriptors.h"
       6  
       7  extern void ctest1 (int iinit, int jinit, CFI_cdesc_t *p);
       8  extern void ctest2 (int iinit, int jinit, CFI_cdesc_t *a);
       9  
      10  struct m {
      11    int i;
      12    int j;
      13  };
      14  
      15  void
      16  ctest1 (int iinit, int jinit, CFI_cdesc_t *p)
      17  {
      18    struct m *mp;
      19    /* Dump the descriptor contents to test that we can access the fields
      20       correctly, etc.  */
      21    dump_CFI_cdesc_t (p);
      22  
      23    if (p->rank != 0)
      24      abort ();
      25    if (p->attribute != CFI_attribute_pointer)
      26      abort ();
      27    if (p->type != CFI_type_struct)
      28      abort ();
      29  
      30    check_CFI_status ("CFI_allocate",
      31  		    CFI_allocate (p, NULL, NULL, sizeof (struct m)));
      32  
      33    if (p->base_addr == NULL)
      34      abort ();
      35  
      36    mp = (struct m *) CFI_address (p, NULL);
      37    mp->i = iinit;
      38    mp->j = jinit;
      39  }
      40  
      41  
      42  void
      43  ctest2 (int iinit, int jinit, CFI_cdesc_t *a)
      44  {
      45    struct m *mp;
      46    /* Dump the descriptor contents to test that we can access the fields
      47       correctly, etc.  */
      48    dump_CFI_cdesc_t (a);
      49  
      50    if (a->rank != 0)
      51      abort ();
      52    if (a->attribute != CFI_attribute_allocatable)
      53      abort ();
      54    if (a->type != CFI_type_struct)
      55      abort ();
      56  
      57    /* The intent(out) allocatable array is supposed to be deallocated
      58       automatically on entry, if it was previously allocated.  */
      59    if (a->base_addr)
      60      abort ();  
      61  
      62    check_CFI_status ("CFI_allocate",
      63  		    CFI_allocate (a, NULL, NULL, sizeof (struct m)));
      64  
      65    if (a->base_addr == NULL)
      66      abort ();
      67  
      68    mp = (struct m *) CFI_address (a, NULL);
      69    mp->i = iinit;
      70    mp->j = jinit;
      71  }