1  #include <stdlib.h>
       2  #include <stddef.h>
       3  #include <stdio.h>
       4  
       5  #include <ISO_Fortran_binding.h>
       6  #include "dump-descriptors.h"
       7  
       8  struct t {
       9    float xyz[3];
      10    int id;
      11  };
      12  
      13  extern void testit_f_bind_c (CFI_cdesc_t *a, float x, float y, float z);
      14  extern void testit_c (CFI_cdesc_t *a, float x, float y, float z);
      15  
      16  void testit_c (CFI_cdesc_t *a, float x, float y, float z)
      17  {
      18    struct t *tp;
      19  
      20    /* Check that the allocatable dummy is unallocated on entry and do
      21       some other sanity checks.  */
      22    dump_CFI_cdesc_t (a);
      23    if (a->attribute != CFI_attribute_allocatable)
      24      abort ();
      25    if (a->rank)
      26      abort ();
      27    if (a->base_addr)
      28      abort ();
      29  
      30    /* Allocate and initialize the output argument.  */
      31    CFI_allocate (a, NULL, NULL, 0);
      32    if (!a->base_addr)
      33      abort ();
      34    tp = (struct t *) CFI_address (a, NULL);
      35    tp->id = 42;
      36    tp->xyz[0] = 0.0;
      37    tp->xyz[1] = 0.0;
      38    tp->xyz[2] = 0.0;
      39  
      40    /* Now call the Fortran function, which is supposed to automatically
      41       deallocate the object we just created above and point the descriptor
      42       at a different object.  */
      43    testit_f_bind_c (a, x, y, z);
      44  
      45    /* Make sure we've got an allocated object, initialized as we
      46       expect.  */
      47    if (!a->base_addr)
      48      abort ();
      49    tp = (struct t *) CFI_address (a, NULL);
      50    if (tp->id != -1)
      51      abort ();
      52    if (tp->xyz[0] != x || tp->xyz[1] != y || tp->xyz[2] != z)
      53      abort ();
      54  }