For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2004 > module procedures









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author module procedures
beliavsky@aol.com

2004-12-13, 9:01 pm

Is it legal Fortran to have an interface where some of the module
procedures (MP) are functions and others are subroutines?

The following code, where y and z are both MP's of x but y is a
subroutine and z is a function, is disallowed by Lahey/Fujitsu, allowed
by g95, and triggers an internal compiler error with CVF 6.6c. I can't
see any use for such code, but I wonder if the compiler is required to
complain about it.

module xx
implicit none
public :: x
private :: y,z
interface x
module procedure y,z
end interface x
contains
!
subroutine y()
end subroutine y
!
real function z()
z = 0.0
end function z
end module xx

Richard E Maine

2004-12-13, 9:01 pm

beliavsky@aol.com writes:

> Is it legal Fortran to have an interface where some of the module
> procedures (MP) are functions and others are subroutines?


No. From 16.2.3 of f2003 (and probably almost the same words in f90/f95)

"Within a scoping unit, two procedures that have the same generic
name shall both be subroutines or both be funcctions..."

> I wonder if the compiler is required to complain about it.


Nope. It isn't a constraint or any of the other things that trigger
such a requirement in the standard. (But I'd say that a "good"
compiler ought to.)

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
James Van Buskirk

2004-12-13, 9:01 pm

<beliavsky@aol.com> wrote in message
news:1102971633.736334.135950@c13g2000cwb.googlegroups.com...

> Is it legal Fortran to have an interface where some of the module
> procedures (MP) are functions and others are subroutines?


ISO/IEC 1539-1:1997(E), section 14.1.2.3 says:
"Within a scoping unit, two procedures that have the same generic name
shall both be subroutines or both be functions, and..."

You may interpret the quoted passage as you wish.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Rich Townsend

2004-12-13, 9:01 pm

beliavsky@aol.com wrote:
> Is it legal Fortran to have an interface where some of the module
> procedures (MP) are functions and others are subroutines?
>
> The following code, where y and z are both MP's of x but y is a
> subroutine and z is a function, is disallowed by Lahey/Fujitsu, allowed
> by g95, and triggers an internal compiler error with CVF 6.6c. I can't
> see any use for such code, but I wonder if the compiler is required to
> complain about it.
>
> module xx
> implicit none
> public :: x
> private :: y,z
> interface x
> module procedure y,z
> end interface x
> contains
> !
> subroutine y()
> end subroutine y
> !
> real function z()
> z = 0.0
> end function z
> end module xx
>


Nope, this is illegal; when an interface block is used to group
procedures together under the same generic name, they must all be
functions or all be subroutines (see, e.g., p. 93 of Fortran 95/2003
Explained).

cheers,

Rich

--
Dr Richard H D Townsend
Bartol Research Institute
University of Delaware

[ Delete VOID for valid email address ]
Steve Lionel

2004-12-14, 9:01 pm

On 13 Dec 2004 13:00:33 -0800, beliavsky@aol.com wrote:

>The following code, where y and z are both MP's of x but y is a
>subroutine and z is a function, is disallowed by Lahey/Fujitsu, allowed
>by g95, and triggers an internal compiler error with CVF 6.6c.


Intel Fortran gets an internal compiler error too with this - we'll fix it.


Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://developer.intel.com/software/products/support/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com