(j3.2006) Optional argument for intrinsics

Daniel C Chen cdchen
Mon May 28 13:04:12 EDT 2012


Questions:

1. Are the optional DIM dummy arguments of intrinsics allowed to be 
associated with disassociated pointer or unallocated allocatable actual 
arguments?
2. Are other optional dummy arguments of intrinsics allowed to be 
associated with disassociated pointer or unallocated allocatable actual 
arguments?


According to the rules defined in section 12.5.2.12, the optional dummy 
argument 'arg' in the following example is not present:

      integer, pointer :: ptr

      nullify(ptr)
      call foo(ptr)

      contains
      subroutine foo(arg)
        integer, optional :: arg
        print *, present(arg)
      end subroutine

      end

This is because the dummy argument 'arg' does not have the POINTER 
attribute, and it corresponds to an actual argument that has the POINTER 
attribute and is disassociated.

The question is whether the same argument presence rules apply to the 
optional DIM argument of some intrinsic procedures. For instance, in the 
following example:

 1    real, allocatable :: array(:,:)
 2    integer, pointer :: ptr
 3 
 4    allocate(array(2,3))
 5 
 6    ... = ubound(array, ptr)
 7 
 8    end

is the result of the ubound on line 6 a scalar or an array?

Since the rank of the result depends on the presence of the DIM argument, 
shouldn't argument association between a disassociated pointer or 
unallocated allocatable and the DIM argument be disallowed?

There are provisions in the standard that disallow optional dummy 
arguments to be associated with the DIM argument. For example

Section 13.2.4, paragraph 1: "The DIM argument of a reduction function is 
not permitted to be an optional dummy argument."

This rule eliminates the uncertainty about the rank of the result of a 
reduction intrinsic at compile-time. One would expect a similar 
restriction for passing a disassociated pointer or unallocated allocatable 
as the actual argument corresponding to the optional DIM argument.

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://j3-fortran.org/pipermail/j3/attachments/20120528/28e8d950/attachment.html>



More information about the J3 mailing list