(root)/
gcc-13.2.0/
gcc/
testsuite/
gfortran.dg/
c-interop/
cf-descriptor-1-c.c
       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 (CFI_cdesc_t *a);
       8  extern void ftest (CFI_cdesc_t *a, CFI_cdesc_t *b);
       9  
      10  struct m {
      11    int i;
      12    int j;
      13  };
      14  
      15  #define imax 10
      16  #define jmax 5
      17  
      18  void
      19  ctest (CFI_cdesc_t *a)
      20  {
      21    
      22    struct m bdata[imax][jmax];
      23    CFI_CDESC_T(2) bdesc;
      24    CFI_cdesc_t *b = (CFI_cdesc_t *) &bdesc;
      25    int i, j;
      26    CFI_index_t subscripts[2];
      27    struct m* mp;
      28  
      29    /* Dump the descriptor contents to test that we can access the fields
      30       correctly, etc.  */
      31    dump_CFI_cdesc_t (a);
      32  
      33    if (a->rank != 2)
      34      abort ();
      35    if (a->attribute != CFI_attribute_other)
      36      abort ();
      37    if (a->dim[0].lower_bound != 0)
      38      abort ();
      39    if (a->dim[0].extent != imax)
      40      abort ();
      41    if (a->dim[1].lower_bound != 0)
      42      abort ();
      43    if (a->dim[1].extent != jmax)
      44      abort ();
      45  
      46    /* Transpose a's contents into bdata.  */
      47    for (j = 0; j < jmax; j++)
      48      {
      49        subscripts[1] = j;
      50        for (i = 0; i < imax; i++)
      51  	{
      52  	  subscripts[0] = i;
      53  	  mp = (struct m *) CFI_address (a, subscripts);
      54  	  if (mp->i != i + 1)
      55  	    abort ();
      56  	  if (mp->j != j + 1)
      57  	    abort ();
      58  	  bdata[i][j].i = mp->i;
      59  	  bdata[i][j].j = mp->j;
      60  	}
      61      }
      62  
      63    /* Fill in bdesc.  */
      64    subscripts[0] = jmax;
      65    subscripts[1] = imax;
      66    check_CFI_status ("CFI_establish",
      67  		    CFI_establish (b, bdata, CFI_attribute_other,
      68  				   CFI_type_struct,
      69  				   sizeof (struct m), 2, subscripts));
      70    
      71    /* Sanity checking to make sure the descriptor has been initialized
      72       properly.  */
      73    dump_CFI_cdesc_t (b);
      74    if (b->version != CFI_VERSION)
      75      abort ();
      76    if (b->rank != 2)
      77      abort ();
      78    if (b->attribute != CFI_attribute_other)
      79      abort ();
      80    if (b->dim[0].lower_bound != 0)
      81      abort ();
      82    if (b->dim[0].extent != jmax)
      83      abort ();
      84    if (b->dim[1].lower_bound != 0)
      85      abort ();
      86    if (b->dim[1].extent != imax)
      87      abort ();
      88  
      89    /* Call back into Fortran, passing both the a and b arrays.  */
      90    ftest (a, b);
      91  }