parameter used to specify kind in function definition fails

This code

program testcode

integer, parameter :: rl = 8

real(rl) mumble
mumble = blah(4.4)

stop
end

real(rl) function blah(x)
blah = 4.4
stop
end

fails to compile with PG version 6.1 on Fedora Core 4

pgf90 testcode.f -o testcode

with the following error message:

PGF90-S-0087-Non-constant expression where constant expression required (testcode.f: 11)
PGF90-S-0081-Illegal selector - KIND parameter has unknown value for data type (testcode.f: 11)
0 inform, 0 warnings, 2 severes, 0 fatal for blah

Which, at the very least, is a poor error message since clearly rl is a constant.

I’m not a Fortran90 programmer and the PG Fortran Reference manual doesn’t specify what type-spec can be in a function definition but it seems like if variable definitions allow parameters to be used then function definitions ought to allow it.

Hi jdk,

You are correct that the first “rl” is constant, however it’s scope is only within the main subroutine testcode. The second “rl” which you use in the blah function’s prefix is in a different scope and hence is implicitly declared as a real variable, not a constant. In order for “rl” be in blah’s scope, you need to have blah contained within testcode.

Example:

program testcode
  implicit none
  integer, parameter :: rl = 8
  real(rl) mumble
  mumble = blah(4.4_rl)
  print *, mumble
  stop

contains 
  real(rl) function blah(x)
    real(rl) x
    blah = x
  end function blah

end program testcode

Hope this helps,
Mat

Thanks for the clarification…I see now that the mistake in my example is just a programming error and it makes sense to me.

I was attempting to boil down the problem I was having with another code into an example appropriate for reporting. I will check to see if there is a similar problem in that code.

In the actual code (zeusmp), the parameter is declared in a module which is used to contain program-wide definitions. The parameter definition seems to work for variable declarations in files which use the module but not for function declarations.

For now I just replaced rl in the function definitions with the actual value which allowed the code to compile and run.