Failure of implicit real*8

N.M. Maclaren nmm1@cam.ac.uk
Sun Feb 20 12:04:00 GMT 2011


On Feb 20 2011, Tobias Burnus wrote:
>
>In the quote above you do not have any IMPLICIT statement, hence, it 
>make sense that MX is typeset as integer. As -fdefault-real-8 only 
>applies to REAL variables/PARAMETER and to real literals, it is thus not 
>effective.
>
>As other have already mentioned: It is recommended to use IMPLICIT NONE 
>and explicitly declare the variables. Doing so avoids difficult to find 
>issues like the one you have.

A historical note that affects newcomers to Fortran:  this used not to
cause such problems, because people thought in terms of implicit typing,
which is why older references ((** and ones that have not moved with the
times **)) sometimes recommend it.  But the Algol approach of explicit
typing proved more reliable, as you say, and no good reference now does.

>Regarding -fdefault-real-8: Note that this option does not influence 
>variables which have been typed with a kind-type parameter, e.g., 
>"REAL*4" remains a 4-byte variable even with that flag.

Using KIND is a lot better, of course, as REAL*4 is not portable.

>Note of caution when not using -fdefault-real-8:  1.0 is a default-real 
>variable, thus for, e.g.,
>   real*8 sqrt
>   sq2 = sqrt(2.0)
>you loose precision, unless you do
>   sq2 = sqrt(2.0d0)

Is it safe for all constants and the problematic intrinsics (like cmplx)?
If so, I may mention it a bit more definitely in my course, more as a
debugging tool than as something to rely on - i.e. if using this works,
look for unmodified constants and intrinsics without kind.


Regards,
Nick Maclaren.



More information about the Fortran mailing list