multiple statements on a single line

multiple statements on a single line


I am in the midst of write a small Fortran library and found a need to define a template for a set of methods and instantiate them using it for different intrinsic types.  With GNU fortran, I did something along the line of the following.

#define TEMPLATE(type_name,size)  \
  TYPE(type_name) FUNCTION PROCNAME(init,type_name) result(o)   ;\
    ...         ;\
  END FUNCTION PROCNAME(init,type_name)                               ;\
  SUBROUTINE PROCNAME(push,type_name)(this) ;                \
    CLASS(type_name), INTENT(INOUT) :: this        ;                 \
    ... ;   \
  END SUBROUTINE PROCNAME(push,type_name)       

This worked O.K. with GNU Fortran 4.8.0.  But ifort 14.0 complains with

 error #5141: END statement must be only statement on line

Is there a work-around to have multiple subroutine definitions in a single line?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You have this:


In the END SUBROUTINE statement, you can name the subroutine but you DON'T repeat the argument list. If gfortran is accepting this, that's their bug,

However... We do seem to have an inappropriate restriction on using "Free form statement termination" with the END statement. I will let the developers know. Issue ID is DPD200248828.

Retired 12/31/2016

Thanks Steve for quick response.

PROCNAME(push,type_name) is actually a macro and it expands to a procedure name.

And, interestingly, ifort is o.k. with 'END TYPE typename' followed by ';' and more statements.

So, I don't have any other way than breaking up the big macro and have each macro definition contain only one procedure/function definition?

Thanks a lot..

I can't think of anything offhand.

Retired 12/31/2016

It turns out that we don't have a bug after all. Interpretation 90/0130 covers exactly this situation where one has something like:


The interpretation reworded the introductory text for free source form from:

"A Fortran program unit is a sequence of one or more Fortran statements, comments and INCLUDE lines."


"A Fortran program unit is a sequence of one or more lines, organized as Fortran statements, comments and INCLUDE lines."

The subtle distinction is that a line cannot contain pieces of more than one program unit.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today