multiple statements on a single line

multiple statements on a single line

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.

#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 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

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.

Steve - Intel Developer Support

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.

Steve - Intel Developer Support

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.

Steve - Intel Developer Support

发表评论

登录添加评论。还不是成员?立即加入