Fortran compiler optimisation (Bill Purvis, ext 3357)
Fri, 11 Nov 1994 13:42:36 GMT

          From comp.compilers

Related articles
Fortran compiler optimisation (1994-11-11)
re: Fortran compiler optimisation 7549-15328 ( (Dennis Ritchie0112710)) (1994-11-14)
Re: Fortran compiler optimisation (1994-11-15)
Re: Fortran compiler optimisation (1994-11-21)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Bill Purvis, ext 3357)
Keywords: question, Fortran, comment
Organization: Daresbury Laboratory, UK
Date: Fri, 11 Nov 1994 13:42:36 GMT

I have recently encountered a bug which appears to be endemic in Fortran
Compilers. At least I think it's a bug. The code which illustrates this

c program to test bug
            print *, fred,george

My reading of the standard implies that the two numbers output should be
pretty near identical. Running on my Sun sparc gives:

          1.78379E-02 5.00000

which is nowhere near!

No doubt there will be plenty of people who can point out what is going
wrong here - the compiler is spotting two constants and is multiplying
them and getting an overflow. However, this is in breach of the standard
which implies that the first constant (1000000) should be converted to
real, multiplied by fred and then by the other constant (500000). Even if
the compiler does optimise this, shouldn't any self-respecting compiler
check for overflows of this kind? I have tried this program on both Sun
and SGI machines and got the same effect. I also tried f2c and noted that
the C code had a single constant which looks nothing like 500000000000.0

Bill Purvis
[F2c does indeed seem to do this wrong, since the F77 standard (and I presume
F90) say that the compiler must respect parens. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.