dmon
dmon

Reputation: 1422

gfortran - assign string to parameter

[NOTE: contains repetition of previous question but posted separately as separate issues]

I am compiling a program which is known to compile with ifort using gfortran. However the compiler fails on the line

PARAMETER (POS='^')  

with the compile error:

conv_prof.mac:9.21:
    Included at conv_prof.f:811:

      PARAMETER (POS='^')                                               
                 1
Error: Can't convert CHARACTER(1) to REAL(4) at (1)
make: *** [conv_prof.o] Error 1

As it turns out the POS parameter is not used (it is likely a legacy parameter) so I may simply uncomment this line to compile, but I would like to know if anyone might have any idea why this is an issue in gfortran and not ifort?

Cheers,

Derek

Upvotes: 0

Views: 1293

Answers (2)

IanH
IanH

Reputation: 21451

The specific extension here is that ifort allows a program to "assign" a character value into a real object. Perhaps it was intended to use this extension - but a more likely explanation is that a type declaration statement for the parameter pos is missing prior to the PARAMETER statement.

Technically I don't think the standard requires a diagnostic in this case (this isn't a violation of the syntax rules or constraints of the standard - it is a violation of the requirements placed on the program in the body text), but you'll get a diagnostic from ifort if you turn on standards checking (/stand or -stand, depending on your platform).

Upvotes: 2

High Performance Mark
High Performance Mark

Reputation: 78364

The Intel compiler is the descendant of a long line of Fortran compilers. Its ancestors implemented all sorts of non-standard behaviour and, in the true spirit of Fortran, the latest versions of the compiler ought to compile the most ancient codes. You can often tell ifort to warn of non-standard features in your codes by judicious use of compiler flags.

gfortran, on the other hand, does not (by default) accept much in the way of non-standard syntax, other than those forms of non-standard syntax which have been so widely used that many unsuspecting programmers think that they are standard forms (eg real*4 and the like).

Your snippet looks to me to come from the days prior to FORTRAN77 when the language didn't really acknowledge the existence of such new-fangled ideas as non-numeric variables. In this case I recommend that you follow gfortran in disallowing this code, rather than Intel Fortran.

Upvotes: 3

Related Questions