(j3.2006) procedure declaration and elementals
Bill Long
longb
Fri Mar 13 19:18:13 EDT 2009
Van Snyder wrote:
> On Fri, 2009-03-13 at 11:44 -0700, Bill Long wrote:
>
>> I got this test case:
>>
>> program f2003_procptr_1
>> implicit none
>> real :: pi = 3.14159265
>> intrinsic :: sin, cos
>>
>> procedure(sin), pointer :: p => NULL ()
>>
>> p => sin
>> print *, "sin(0), sin(pi/2) =", p(0.0), p(pi/2)
>>
>> p => cos
>> print *, "cos(0), cos(pi) =", p(0.0), p(pi)
>>
>> end program f2003_procptr_1
>>
>>
>>
>> The procedure declaration statement appears to violate C1219
>> (09-007:[291:26-27]). What is the rationale for this constraint? Is
>> the code nonconforming?
>>
>
> C732 prohibits a <proc-target> to be a nonintrinsic elemental procedure.
>
> 7.2.2.4p3 says "<proc-target> may be an elemental intrinsic procedure
> even if <proc-pointer-object> is not elemental.
>
p4 of the same section says "If the characteristics of
<proc-pointer-object> or <proc-target> are such that an explicit
interface is required [which would include being elemental], both
<proc-pointer-object> and <proc-target> shall have an explicit
interface." In particular, the interface for an intrinsic is always
explicit, so any procedure pointer associated with an intrinsic (if
such an association were allowed) would have to have an explicit
interface. The way for a procedure pointer to have an explicit
interface is for it to be declared in a procedure declaration
statement. So, if elemental procedure pointers are allowed at all, it
would seem that a declaration like the one above has to be allowed.
But....(see below).
> Notwithstanding 7.2.2.4p3, it appears, however, that C1219 prohibits
> elemental procedure pointers and elemental dummy procedures.
Yes. That was my reading. Given the similarity between procedure
pointers and dummy procedures, it makes sense that they are treated the
same.
> I think
> instead of "shall specify an external procedure" it should have been
>
> "C1219 (R1215) If <proc-interface> describes an elemental procedure,
> <proc-entity-name> shall not be a <dummy-arg-name>." There is nothing
> similar, however, concerning interface bodies, i.e., nothing like
>
Is there a reason for treating dummy procedures and procedure pointers
differently here?
> C1205a (R1205) An <interface-body> for a dummy procedure shall not
> describe an elemental procedure interface."
>
> While researching this, I came upon 12.5.2.9p5, which ends "...may be
> associated with a dummy procedure (which is prohibited from being
> elemental)."
>
Well spotted. But the model for procedure pointers was dummy
procedures. If dummy procedures are not allowed to be elemental, then
procedure pointers should not either. This seems consistent with the
wording at the beginning of 12.8.1 (09-007:318:3-4]):
"An elemental procedure is an elemental intrinsic procedure or a
procedure that is defined by an elemental subprogram." Neither a dummy
procedure nor a procedure pointer is "defined by a ... subprogram".
It seems that neither is allowed to be elemental. (Which is consistent
with the current C1219.)
So, at this point my conclusion is that the original program is not
conforming because of the procedure declaration statement. It also
seems that an intrinsic elemental procedure cannot be the target of a
procedure pointer.
Cheers,
Bill
> I couldn't find where dummy procedures are prohibited from being
> elemental (I looked at every occurrence of "elemental" in 09-007). I'm
> confident we had something explicit at some time. I also looked through
> 04-007 and couldn't find it. If it actually has escaped, we need
> something like
>
> "C1255a (R1230) A <dummy-argument-name> shall not be the name of an
> elemental dummy procedure."
>
> which would be better than saying it twice, in C1205a and C1219.
>
>
>> Cheers,
>> Bill
>>
>
>
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
>
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120
More information about the J3
mailing list