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

Daniel C Chen cdchen
Wed Jul 17 14:30:55 EDT 2013


Thanks Reinhold!

It is also how we understand although the wording for the 2nd case (C
actual that corresponds to Fortran dummy) could be a bit more clearer by
specifying it only applies if  CFI_establish() has never been executed.

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



From:	"Bader, Reinhold" <Reinhold.Bader at lrz.de>
To:	fortran standards email list for J3
            <j3 at mailman.j3-fortran.org>,
Date:	07/17/2013 13:59
Subject:	Re: (j3.2006) Question about formal parameter dv  of
            CFI_establish
Sent by:	j3-bounces at mailman.j3-fortran.org



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
_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org
http://mailman.j3-fortran.org/mailman/listinfo/j3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20130717/cf788e9a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
Url : http://mailman.j3-fortran.org/pipermail/j3/attachments/20130717/cf788e9a/attachment.gif 



More information about the J3 mailing list