Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In the following, I'll explain using the complete example below (which you can compile and link to try things):</p> <pre><code>module mymodule contains integer function foo () foo = 1 end function integer function bar () integer :: foo bar = foo() end function end module program test use mymodule print *, bar() end </code></pre> <p>In the code of function <code>bar</code>, the declaration <code>integer :: foo</code> is strictly equivalent to:</p> <pre><code>integer, external :: foo </code></pre> <p>Thus, in the code of <code>bar</code>, you are explicitly stating:</p> <blockquote> <p><em>"there may already be a symbol of name <code>foo</code> accessible to you, but from now on, when I use it I mean it to be an external function of this name"</em></p> </blockquote> <p>So, this is valid code, and the compiler just expect you to provide an <code>external</code> function named <code>foo</code>. Because you don't (the module function isn't external), it fails to link. You can provide an external <code>foo</code> function by adding the following code (not in the module, just at the end of the same file):</p> <pre><code>integer function foo () foo = 42 end function </code></pre> <p>If you add this function body, then your code will compile, and the output will be <code>42</code> (as the external function is called, not the module function).</p> <p>Also worth noting, if you comment out <code>integer :: foo</code> line in the code of <code>bar</code>, symbol <code>foo</code> will resolve to the module function, which will then be called whether or not you provide an external function named <code>foo</code> (thus, the output will be <code>1</code>).</p> <p><strong>Conclusion:</strong> not a compiler bug, but misuse of an old feature of the language (external declarations). To be honest, I think it's better to explicitly mark your <code>external</code> declarations as such, which would at least have highlighted the issue here.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload