Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messagebeliavsky@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
Post Follow-up to this message<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
Post Follow-up to this messagebeliavsky@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 ]
Post Follow-up to this messageOn 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/
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.