PROCEDURE declarations

Janus Weil jaydub66@googlemail.com
Wed Aug 22 21:53:00 GMT 2007


2007/8/21, Tobias Burnus <burnus@net-b.de>:
> You mean something like the following?
>
> !  integer, external :: sub
>   real, external sub
>   integer :: i
>   i = sub()
> end
>
> This is valid as the value returned by sub (i.e. REAL) can be converted
> into INTEGER.
>

Well, that's not quite what I mean. Consider the following code, which
gives some examples of what the procedure declaration patch can handle
at this point:


integer function p1()
  p1 = 5
end function

integer function p2()
  p2 = 6
end function

subroutine p3()
  print *,"p3"
end subroutine

subroutine p4()
  print *,"p4"
end subroutine

integer function p5()
  p5 =8
end function

program p
  implicit none

  abstract interface
    subroutine abssub()
    end subroutine
  end interface

  procedure(integer):: p1
  procedure(fun):: p2
  procedure(abssub):: p3
  procedure(sub):: p4
  procedure(real):: p5
  print *, p1()
  print *, p2()
  call p3()
  call p4()
  print *,p5()

contains

  integer function fun()
    fun=7
  end function

  subroutine sub()
    print *,"sub"
  end subroutine

end program p

module m
  procedure():: mp1
  procedure(real), private:: mp2
  procedure(mfun), public:: mp3
contains
  real function mfun()
    mfun=4.2
  end function
end module


The procedure p5 illustrates what I mean: It is declared as real, but
its actual implementation returns an integer. And this integer is not
correctly converted to a real: Instead of "8" the line "print *,p5()"
gives me the output "NaN". This happens for both PROCEDURE and
EXTERNAL.
Should I make any attempt to check matching types in cases like this?
And is it even possible?

I also implemented some new checks (e.g. for C1204, C1217 and C1218)
in my patch, which you find attached. It should be able to cover a
broad spectrum of procedure declarations by now and also includes my
recent bugfixes for abstract interfaces. I will post some more
testcases for the patch soon.
Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: procdecl127707.diff
Type: text/x-patch
Size: 13839 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070822/35f12cbd/attachment.bin>


More information about the Fortran mailing list