(j3.2006) separate module procedures question

Bill Long longb
Tue Dec 22 11:33:45 EST 2009


We got an interesting variant on separate module procedures, which can 
be reduced to this test case:

module modu

   interface
     module function rst(x)                 ! okay
       real :: x
     end function rst

     module subroutine rst_1(x)             ! okay
       real :: x
     end subroutine rst_1
   end interface

contains

   function rst(x)                          ! Error -> Needs module 
prefix  ??
   real :: x
   rst = 6*3.14
   end function

   subroutine rst_1(x)                      ! Error -> Needs module 
prefix ??
   real :: x
   end subroutine
end module modu


it is pretty clear what the user intended here (an intermediate step in 
converting to using submodules), and the compiler can easily generate 
unambiguous code.  However, it appears to be illegal.

The rules are that an interface body that begins 'module
subroutine...' or 'module function...' specifies the interface for a
"separate module procedure" [281:20-21].  A "separate module procedure"
is a procedure whose definition begins with  'module subroutine...',
'module function...', or 'module procedure...'. [309:21-23].

I could see three candidate answers for an interp question [Was this 
intended to be conforming?]  for this case:

1)  The definition of "separate module procedure" should have made the
MODULE optional if the procedure is defined in the same module as its
corresponding separate interface body.  If that were the case, the code
is fine, and clear as to what is intended.

2) The defined procedures (which are not separate module procedures) are
different from the ones (which are separate module procedures) specified
by the interfaces, in which case they effectively cannot be referenced.
You have essentially specified two different procedures that have the 
same name.
I think this would be confusing for users.

3) The program has a syntax error.  The procedure definitions require
the MODULE prefix in their initial lines.


Answer (3) is simplest, but did we ever consider option (1)?


Cheers,
Bill




-- 
Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list