3

I have a Fortran90 code that compiles and works great with gfortran 4.8.5. However, when I try to compile it with newer gfortran versions (I've tested from 6.3 to 11.2), it does not work!!

If I don't add any flags to gfortran-6.3+, I get Error: Blank required in STOP statement near (1).

If I add -std=f95, then I get Error: GNU Extension: Nonstandard type declaration or Error: Fortran 2003: Elemental function as initialization expression with non-integer/non-character arguments...

Any tips? Thanks!

3
  • 2
    You must show your code. It probably isn't a code conforming to the Fortran standard. Commented May 2, 2022 at 21:05
  • 2
    What happens if you actually insert a blank in the line? Why would you think asking for stricter conformance to the Fortran 95 standard would accept the code? Commented May 2, 2022 at 22:07
  • In addition to my first comment, yo also always have to show the complete error output. Not just one line. I am 100% sure that the compiler did quote the problematic line. Commented May 3, 2022 at 12:36

1 Answer 1

2

The source

stop1
end

is not a valid Fortran 90/95/2003/2008/2018 program.

It is, however, a program that is accepted by GCC 4.8.5, seemingly with the intended result.

It is accepted by this version of the compiler because it does not have the diagnostic capability to reject the program. Later versions of GCC do include such capability.

No compiler is required to have this capability: the error in this source is one the programmer must take responsibility for. By using a newer compiler you are taking advantage of the improvements in its optional error checking focus. One should be grateful to a compiler which points out mistakes even when it doesn't have to.

If you have broken code like my example here: fix it. Using the flag -std=f95 for later versions of GCC won't help: the flag requests checking for stricter conformance to the Fortran 95 standard (against allowing non-standard extensions or features from Fortran 2003+) but as above, the code is not valid Fortran 95 code.


Note, however, that

      stop1
      end

is a valid Fortran 90+ program in fixed-form source. If you're trying to compile fixed-form source as free-form source, then as above early versions of GCC will accept it while later versions will reject it. In this case, explicitly tell the compiler to compile as fixed-form source or change the source to be valid so-called intersection format.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.