To: J3 11-122r2 From: John Reid Subject: Interop: Example re changing attributes Date: 2011 February 1 References: N1838, N1844, ISO/IEC 1539-1:2010 DISCUSSION The Fortran programmer might pass an array with one attribute, say allocatable, to an array with another, say assumed-shape. The Fortran system takes care of this. From C, the C programmer needs to do a bit of work. Edits are provided to show an example. EDITS to N1838: [21:17+] At the start of A.2 Clause 5 notes, add the subsection title "A.2.1 Dummy arguments of any type and rank" [22:33+] Add A.2.2 Changing the attributes of an array A C programmer might want to call more than one Fortran procedure and the attributes of an array involved might differ between the procedures. In this case, it is desirable to set up more than one C descriptor for the array. For example, this code fragment initializes two C descriptors of rank 2, calls a procedure that allocates the array described by the first descriptor, copies the base_addr pointer and dim array to the second descriptor, then calls a procedure that expects an assumed-shape array. CFI_DESC_T(2) loc_alloc, loc_assum; CFI_cdest_t * desc_alloc = (CFI_cdest_t *)&loc_alloc, * desc_assum = (CFI_cdest_t *)&loc_assum; int rank = 2, flag; flag = CFI_initialize_cdesc (desc_alloc, sizeof(double), rank, CFI_type_double, CFI_attribute_allocatable); flag = CFI_initialize_cdesc (desc_assum, sizeof(double), rank, CFI_type_double, CFI_attribute_assumed); Fortran_factor (desc_alloc, ...); desc_assum->base_addr = desc_alloc->base_addr; (void) memcpy (desc_assum->dim, desc_alloc->dim, rank*sizeof(CFI_dim_t)); Fortran_solve (desc_assum, ...);