Obsolescent character function (Cygwin)
Brooks Moses
bmoses@stanford.edu
Mon Sep 11 23:22:00 GMT 2006
Angelo Graziosi wrote:
> When I build the following simple test case
[...]
> I have:
>
> -------------------------------------
> In file prova.F95:8
>
> function chfun(x)
> 1
> Warning: CHARACTER(*) function 'chfun' at (1) is obsolescent in fortran 95
>
> --------------------------------------
>
> Why is 'chfun' obsolescent ?
Because it has a return value that is declared as an assumed-length
character string, and the Fortran 95 Language Standard states that
functions with assumed-length character return values are an obsolecent
feature of the language.
The standard states that features are declared to be obsolescent only
when better methods for achieving the same functionality exist (and
existed in the previous standard as well), and when "it is recommended
that programmers should use these better methods in new programs and
convert existing code to these methods."
One possible rewriting of your code would be to pass the result length
in as an argument:
--------------------------------------------
program prova
implicit none
character(len = 10) :: chfun
write(*,*) chfun(5),chfun(25)
contains
function chfun(x,n)
integer :: x,n
character(len=n) :: chfun
write(chfun,'(I10)') x
end function chfun
end program prova
--------------------------------------------
Note that this change does require that the program have an "explicit
interface" for chfun. The easiest way to accomplish that is containing
chfun within the main program as I've done, but you could also put chfun
in a module that's used within the main program, or declare an interface
block to it within the main program.
- Brooks
More information about the Fortran
mailing list