Re: Assumed-shape arrays and dummy procedures



On Apr 6, 3:56 am, "James Van Buskirk" <not_va...@xxxxxxxxxxx> wrote:
      subroutine callthru(qsub, option)
         implicit logical(q)
         integer, intent(in) :: option
         external qsub

         if(option == 1) then
            write(*,'(a)') 'Calling subroutine A'
            call A(qsub, 2)

"A" takes a subroutine as argument.

         else if(option == 2) then
            write(*,'(a)') 'Calling subroutine B'
            call B(qsub, 2)

While "B" takes a function as argument.

I believe the program is invalid. Quoting the Fortran 2003 standard:

"12.4.1.3 Actual arguments associated with dummy procedure entities"
[...]
"If the interface of the dummy argument is implicit and either the
name of the
dummy argument is explicitly typed or it is referenced as a function,
the dummy
argument shall not be referenced as a subroutine"

As you once reference "qsub" as function and once as subroutine (by
using them as actual argument), the program is invalid and the
compiler is free to reject it. Interestingly, most compiler accept a
reduced version which contains such calls. For the most reduced
version which uses implicit typing, of my compilers, only gfortran
rejects it. For the full program, most of my compilers reject it.

In conclusion, I think gfortran is right and your program is invalid.


      subroutine  A(sub, n)
         integer, intent(in) :: n
         interface
            subroutine sub(x)
               implicit none
               real, intent(in) :: x(:)
            end subroutine sub
         end interface

      subroutine B(sub, n)
         integer, intent(in) :: n
         interface
            function sub(x)
               implicit none
               integer, intent(in) :: x
               logical sub(x)
            end function sub
         end interface

Tobias
.



Relevant Pages

  • Re: Inserting data in linked lists
    ... TYPE, POINTER:: head, tail ... SUBROUTINE get_values ... this is not valid since the associated dummy argument has the ... so I dont' really understand why the compiler is ...
    (comp.lang.fortran)
  • Re: Help on use Module and Interface in Fortran 95
    ... >> fixed size in the common block. ... > that you can't have something both be a dummy argument and in common ... > the same subroutine. ... > I have the same confusion as the compiler will. ...
    (comp.lang.fortran)
  • Re: DPROD issues
    ... a switch like that typically ... makes a compiler nonstandard in that mode. ... treatment of specific intrinsics is one ... subroutine sub1a ...
    (comp.lang.fortran)
  • Re: Jumping into block of an if construct
    ... (For that matter a clever enough compiler could replace this PUT DATA ... routine which itself executes the loops around element handling. ... Either way I think the cost of element handling will usually ... So locally based on subroutine arguments, but not on, for example, ...
    (comp.lang.fortran)
  • Re: Q: Checking the size of a non-allocated array?
    ... an actual argument is already invalid ... First note that you don't have an unallocated array in the subroutine. ... it is comparable to disassociated or undefined pointers. ... Obviously the compiler has ...
    (comp.lang.fortran)