(j3.2006) Question about formal parameter dv of CFI_establish

Bader, Reinhold Reinhold.Bader
Wed Jul 17 13:55:44 EDT 2013


Hello Daniel,

sorry for being a bit late in answering this.

Paper 11-225r1 has a rationale for the formulation "It shall not have the same value as either a C formal parameter that corresponds to a Fortran actual argument or a C actual argument that corresponds to a Fortran dummy argument." by providing a number of examples the rule is designed to prevent. My understanding is that the condition must hold at the point where CFI_establish() is executed.


My opinion on the validity of your two examples is:

The example Q1 is not conforming, because the Fortran procedure fortran_foo expects a well-defined
descriptor which is not provided. CFI_establish() must be invoked on cp before the Fortran procedure is.

The example Q2 appears to be conforming. A descriptor is allowed to be re-established provided the conditions on invocation of CFI_establish() are fulfilled, which I think is the case.

Best regards
Reinhold




________________________________
Von: j3-bounces at mailman.j3-fortran.org [j3-bounces at mailman.j3-fortran.org]" im Auftrag von "Daniel C Chen [cdchen at ca.ibm.com]
Gesendet: Donnerstag, 11. Juli 2013 21:34
An: j3 at mailman.j3-fortran.org
Betreff: (j3.2006) Question about formal parameter dv of CFI_establish


Hello ,

In the C-interop TS, it says the following about the formal parameter dv of CFI_establish:

dv shall be the address of a C object large enough to hold a C descriptor of the rank speci ed by rank. It shall
not have the same value as either a C formal parameter that corresponds to a Fortran actual argument or
a C actual argument that corresponds to a Fortran dummy argument. It shall not be the address of a C
descriptor that describes an allocated allocatable object.

Q1: is the following test case legal?  (it seems now according to the wording quoted at the above).

void func(CFI_cdesc_t *target)
{
  int ind;
  CFI_index t lower_bounds[CFI_MAX_RANK] = {0};
  CFI_CDESC_T(CFI_MAX_RANK) p;
  CFI_cdesc_t *cp = (CFI_cdesc_t *) &p;

 fortran_foo(cp); /*cp  is  passed as an actual argument  that corresponds to a Fortran dummy argument.*/

 ind = CFI_establish(cp, NULL, CFI_attribute_pointer, target->type, target->elem_len, target->rank, NULL);

}


Q2:  is the following  code fragment legal? (The 2nd CFI_establish  seems fine to me, but does it violate the wording quoted at the above?)

void func(CFI_cdesc_t *target)
{
  int ind;
  CFI_index t lower_bounds[CFI_MAX_RANK] = {0};
  CFI_CDESC_T(CFI_MAX_RANK) p;
  CFI_cdesc_t *cp = (CFI_cdesc_t *) &p;

 ind = CFI_establish(cp, NULL, CFI_attribute_pointer, target->type, target->elem_len, target->rank, NULL);

 fortran_foo(cp); /*cp  is  passed as an actual argument  that corresponds to a Fortran dummy argument. after it is established.*/

 ind = CFI_establish(cp, NULL, CFI_attribute_pointer, target->type, target->elem_len, target->rank, NULL); /*can it be  established again?*/

}

Thanks,

Daniel

XL Fortran Development - IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20130717/0271a9e6/attachment-0001.html 



More information about the J3 mailing list