- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can I call the subroutine in a module twice?
I have a module as
Module name1
Contains
Subroutine name2()
End Subroutine name2
Subroutine name3()
Callname2()
Call name2()
End Subroutine name3
End Module name1
I try to call Subroutine name2() in Subroutine name3 twice as in above code, but there is an linking error, saying that name2 is an external function. However, if name2 is called one time only, the code can work. Why is that? Thanks.
Actually, in the code I am using 'Call name2()', rather than 'Call subroutine name2()'I've made a mistake in the previous post. Sorry about that.
Since my IDE is not in English, I cannot give the exact error message here, but it means that the code can not be linked to the subroutine name2()
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should only have
Call name2()
Otherwise, you are trying to call an unknown subroutine called subroutinename2() - Fortran ignores the blanks in the name.
- 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
The "Call Subroutine name2()" part is wrong. It should only be "call name2()".
Had the code been in free source form, a syntax error message would have shown you that only one word is expected between the "Call" keyword and the "(", so that "name2" is considered redundant.
With code in fixed source form, spaces are ignored, so the compiler assumes there's a subroutine called Subroutinename2. The fact that the code compiles, doesn't mean that it works ---since the linker will have a hard time trying to find the symbol SUBROUTINENAME2 (or NAME3_MP_SUBROUTINENAME2, or something like that).
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page