using Fortran77 I came upon some code that uses a 'trick' to do dynamic procedure calls.
I did some tests and actually wondered why the compiler (ifort 14.0) silently compiles this code? The code even works, be it that it clearly does not adhere to the standard and has a couple of pitfalls. Should not the compiler have issued a type mismatch error here like: error #6633: The type of the actual argument differs from the type of the dummy argument. [%VAL] ?
! compile with ifort f77_test.F90 ! ! run a.out ! module mod_f77_test implicit none integer :: idata end module mod_f77_test program f77_test use mod_f77_test procedure() :: func, sub call storename('func',func) call callproc(%val(idata)) call storename('sub',sub) call callproc(%val(idata)) stop end program f77_test subroutine storename(name, proc) use mod_f77_test character*(*) :: name procedure() :: proc write(*,'('' Store pointer for procedure '',A)') name idata = %loc(proc) end subroutine subroutine callproc(proc) procedure() :: proc call proc return end subroutine integer function func() write(*,'('' now in func '')') func = 1 return end function subroutine sub() write(*,'('' now in sub '')') return end subroutine
Store pointer for procedure func now in func Store pointer for procedure sub now in sub
Unless you ask for checking the code for non-standard features, Ifort will attempt to compile the source and emit code that will do what the user asked for.
Try the -warn all and -stand f03 options.
Careful with your above program.
If you port that to 64-bit, INTEGER IDATA would no longer be able to hold the procedure pointer.
The intention of the no warning is to permit compiling of legacy programs (that work) and do not overburden the user with
"Warning Will Rogers..." messages for program structure that was perfectly
valid functional decades ago.
.. using Fortran77 I came upon some code that uses a 'trick' to do dynamic procedure calls. .. Should not the compiler have issued a type mismatch error here like: error #6633 ..
As mentioned upthread, you can get the compiler to issue errors and warnings by turning on appropriate compile-time options:
But a question: when you write "using Fortran77", can you please elaborate what you mean?
As you indicate, the code in the original post does not conform to any Fortran standard revision, neither the so-called FORTRAN 77 nor the latest one termed "Fortran 2018". So do you need the code to be FORTRAN 77 compliant? You will know the current Fortran standard offers facilities to readily handle the apparent use case in the code you show i.e., one does not necessarily need to use the non-standard %VAL and %LOC options, etc.