A tale of three compilers

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sat Dec 4 23:28:00 GMT 2004


Paul Thomas wrote:
>>See note 14.13 and paragraph 14.6.2.1.3 no. 3 in the Fortran 95 standard. 
>>The
>>status of base%this is undefined after leaving the subroutine.
>>
> 
> That was the reason I wrote the message - In gfortran, it manifestly is 
> undefined; correctly, as you are saying.  In other brands, it remains 
> defined and, in fact, the variable j survives intact.

The association status per the standard is 'undefined' -- this doesn't mean
'disassociated', but is a third alternative.  See 14.6.2.1.: a pointer can
have any of three association states: associated, disassociated, or undefined.
 There is no correct result for your program.

With the other compilers I assume that you're only being unlucky.  If you
print the output from a subroutine instead of the main program, or if check()
were not a contained subroutine, it's possible that you get different results
from all compilers because the program would modify the stack.  Turning on
optimization might also change the output.

> There was an implicit question in what I wrote, about gfortran: What is the 
> overhead involved in cleaning up correctly?

Assuming with 'cleaning up' you mean nullifying all pointers pointing to local
variables at the end of subroutines, I doubt this is feasible.

- Tobi



More information about the Fortran mailing list