This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Failure of implicit real*8


Michael D. Berger wrote:
Using:
    gfortran44 -fdefault-real-8

I have two nearly identical subroutines very similar to:
    subroutine orderRows(mx, idxSort, nrows, ncols)
    dimension idxSort(nrows),mx(nrows,ncols),tmp(nrows,ncols)
    ...
where mx is expected to be real, in particular, real*8 because
of the compile option.

But one of the two interprets mx as an integer, giving
radically wrong results.

Without an IMPLICIT statement, one has:
IMPLICIT REAL(A-H, O-Z), INTEGER(I-N)
Thus, "MX" is implicitly type as INTEGER. You need to either explicitly type MX as REAL (or REAL*8) or you have to add an IMPLICIT statement for "M" which types it as REAL.


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.

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.

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)


Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]