- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By having a typo I found something that I feel to be a compilererror.
I have isolated it in a small example program that is given below.
[bash] MODULE de ! CONTAINS ! INTEGER FUNCTION m1(n) IMPLICIT none INTEGER,INTENT(in) :: n ! INTEGER :: m2 ! <<< problem line m1=m2(n)**2 RETURN END FUNCTION m1 ! INTEGER FUNCTION m2(n) IMPLICIT none INTEGER,INTENT(in) :: n m2=10*n RETURN END FUNCTION m2 ! END MODULE de ! ! PROGRAM cep USE de IMPLICIT none write(*,*) m1(1) write(*,*) m1(2) END ! "stand alone" external function m2 ! INTEGER FUNCTION m2(k) ! IMPLICIT none ! INTEGER,INTENT(in) :: k ! m2=k ! RETURN ! END[/bash]
If the "problem" line is commented out, and the external function m2 is
commented out (lower part of the source), everything wents fine.
The main program calls m1 and m1, in turn, calls m2. And the answers are
100 and 400 as expected.
Now (here is the typo) if there is a definition of a function m2
in the module procedure m1, the compilers translates fine, but the linker
protests saying it could not find the symbol _M2 referenced in function _DE_mp_M1.
This looks strange to me: there now are two functions m2, one in the form of
an external function (not resolved) and another as a module procedure.
Should the compiler alarm on this definition doublure mentioned?
In the next step, if we add such a function (see lower part of the source),
and leaving the m2 definition in m1 intact, there is neither an error in compiling
nor an error in linking (no unresolved external reference). The program uses
the stand-alone external function m2 and returns the answers 1 and 4.
The external procedure seems to have preference above the module procedure.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"Inner calls another internal procedure that is a function, f; it must not contain a type specification for that function."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am afraid that I am not the first one that made this mistake. Your remarks are clear. My suggestion that the compiler could be wrong is, in retrospect, a little silly as theissueis since Fortran 90 in the compiler. Sorry for that!
Thanks for your help.
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Furthermore, in this instance, good habits (declaring types, possibly to the point of redundancy) did not go unpunished.
Perhaps the compiler could nudge the programmer, saying "redelaration of variable type hides earlier declaration" or something similar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page