1  #include <stdlib.h>
       2  #include <stdio.h>
       3  
       4  #include <ISO_Fortran_binding.h>
       5  #include "dump-descriptors.h"
       6  
       7  extern void ftest (int n, CFI_cdesc_t *a, int *b, char *c, double *d);
       8  extern void ctest1 (CFI_cdesc_t *a, int *b, char *c, double *d);
       9  extern void ctest2 (int n, CFI_cdesc_t *a, int *b, char *c, double *d);
      10  
      11  static void *aa;
      12  static int *bb;
      13  static char *cc;
      14  static double *dd; 
      15  
      16  extern void
      17  ctest1 (CFI_cdesc_t *a, int *b, char *c, double *d)
      18  {
      19    /* Cache all the pointer arguments for later use by ctest2.  */
      20    aa = a->base_addr;
      21    bb = b;
      22    cc = c;
      23    dd = d;
      24  
      25    /* Test calling back into Fortran.  */
      26    ftest (0, NULL, NULL, NULL, NULL);
      27    ftest (1, a, NULL, NULL, NULL);
      28    ftest (2, a, b, NULL, NULL);
      29    ftest (3, a, b, c, NULL);
      30    ftest (4, a, b, c, d);
      31  }
      32  
      33  extern void
      34  ctest2 (int n, CFI_cdesc_t *a, int *b, char *c, double *d)
      35  {
      36    if (n >= 1)
      37      {
      38        if (!a)
      39  	abort ();
      40        if (a->base_addr != aa)
      41  	abort ();
      42      }
      43    else
      44      if (a)
      45        abort ();
      46  
      47    if (n >= 2)
      48      {
      49        if (!b)
      50  	abort ();
      51        if (*b != *bb)
      52  	abort ();
      53      }
      54    else
      55      if (b)
      56        abort ();
      57  
      58    if (n >= 3)
      59      {
      60        if (!c)
      61  	abort ();
      62        if (*c != *cc)
      63  	abort ();
      64      }
      65    else
      66      if (c)
      67        abort ();
      68  
      69    if (n >= 4)
      70      {
      71        if (!d)
      72  	abort ();
      73        if (*d != *dd)
      74  	abort ();
      75      }
      76    else
      77      if (d)
      78        abort ();
      79  
      80  }
      81  
      82