For Programmers: Free Programming Magazines  


Home > Archive > Fortran > May 2005 > module procedure in main program









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 procedure in main program
John Harper

2005-05-25, 8:57 pm

The following program is bad f95 because it has a MODULE PROCEDURE
declaration in a main program instead of in a module, where one is
declaring a generic name for which the specific procedures are
internal. But did the standard have to disallow that? Some compilers
allow it,presumably as a language extension, printing
complex case sqr((0,2)) = (-4.000000,0.0000000E+00)
real case sqr( 2.0) = 4.000000
as I had expected.

PROGRAM squaring
INTERFACE sqr
MODULE PROCEDURE rsqr,csqr
END INTERFACE
REAL x
COMPLEX z
PRINT*,'complex case sqr((0,2)) =',sqr((0,2))
PRINT*,'real case sqr( 2.0) =',sqr( 2.0 )
CONTAINS
REAL FUNCTION rsqr(x)
REAL,INTENT(IN)::x
rsqr = x**2
END FUNCTION rsqr
COMPLEX FUNCTION csqr(z)
COMPLEX,INTENT(IN)::z
csqr = z**2
END FUNCTION csqr
END PROGRAM squaring

Unless that could cause some ambiguity which I have failed to see,
I suggest that f2008 either allow it, or introduce a new keyword
INTERNAL PROCEDURE that one could use in an interface block in a
main program or an external subprogram when, as above, the specific
procedures it refers to are internal.

The same issue could not arise in an internal subprogram unless f2008
allows them to contain internal subprograms.

John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045
Richard E Maine

2005-05-25, 8:57 pm

In article <1117058512.635442@bats.mcs.vuw.ac.nz>,
harper@mcs.vuw.ac.nz (John Harper) wrote:

> The following program is bad f95 because it has a MODULE PROCEDURE
> declaration in a main program instead of in a module, where one is
> declaring a generic name for which the specific procedures are
> internal. But did the standard have to disallow that?

....
> Unless that could cause some ambiguity which I have failed to see,
> I suggest that f2008 either allow it, or...


You don't have to wait for f2003 for a better fix than that. You have to
wait a long enough for f2003 implementations to come out, but not for
f2008 ones. The module procedure statement had several other annoyances.
For example, you couldn't put an external procedure into two different
generics in the same scoping unit. That's because you couldn't use a
module procedure statement (it not being a module procedure), and using
two interface bodies gave you duplicate declaration errors.

The whole business about restricting it to module procedures is just
silly. All you should need is for the procedure to have an explicit
interface - details of how that happened are unimportant.

In f2003 the keyword "module" is optional. It is just plain a PROCEDURE
statement. YOu can throw the MODULE keyword in for compatibility, but I
can't think of much other reason to do so. If you use the optional
MODULE keyword, then you have the same silly constraint as in f95. If
you leave the MODULE keyword off, it can be anything with an explicit
interface. That includes module procedures, internal procedures, dummy
procedures, procedure pointers (I think - would have to check that one
to be sure), or external procedures. In some cases like external
procedures, you would have had to provide an explicit interface
otherwise.

--
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
Sponsored Links







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

Copyright 2009 codecomments.com