Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

multiple statements on a single line

Wooyoung_K_Intel
Employee
2,214 Views

Hi,

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.

[cpp]#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)       [/cpp]

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?

0 Kudos
4 Replies
Steven_L_Intel1
Employee
2,214 Views

You have this:

END SUBROUTINE PROCNAME(push,type_name)

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.

0 Kudos
Wooyoung_K_Intel
Employee
2,214 Views

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..

0 Kudos
Steven_L_Intel1
Employee
2,214 Views

I can't think of anything offhand.

0 Kudos
Steven_L_Intel1
Employee
2,214 Views

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

END; SUBROUTINE S

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."

to:

"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.

0 Kudos
Reply