[J3] END statement

Steidel, Jon L jon.l.steidel at intel.com
Mon Dec 5 21:17:07 UTC 2022


Consider the following two source lines:

      subroutine sub (); end subroutine; integer i
      end program

I have access to four compilers.  Two of them error stating that the END statement must be the only statement on the line, pointing to the END SUBROUTINE statement on line 1.  A third errors stating that an END statement must be the last statement on the line, also pointing to the END SUBROUTINE statement.  The fourth silently compiles the program without error.

These errors occur if the program is compiled as fixed or free form.
,
The only restrictions I find on an END statement are in fixed format.  6.3.3.5 Fixed source format, the final two sentences of paragraph 1 state

                The program END statement shall not be continued.  A statement whose initial line appears to be a program unit END statement shall not be continued.

6.3.1 Program units, statements, and lines applies to both source formats, and says:

                A Fortran program unit is a sequence of one or more lines, organized as Fortran statements, comments and INCLUDE lines.
                A line is a sequence of zero or more characters.  Lines following a program unit END statement are not part of that program
                unit.  A Fortran statement is a sequence of one or more complete or partial lines.

The fixed source form restrictions were in FORTRAN 77.  Prior to FORTRAN 77 there were only END statements, no ENDIF, and no END SUBROUTINE, END FUNCTION, END PROGRAM statements. ENDIF was introduced in F77, the others listed in F90.  F77 had no statement separators.

It seems to me the code above should be standard conforming.  It surprised me that most of the compilers I tried did not accept it.  I am curious if other compilers accept it, and if I am missing some restriction on END statements that would prohibit this code from conforming.

Regards,

-jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221205/35a61472/attachment.htm>


More information about the J3 mailing list