Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
232 Views

Fortran compiler accepts type mismatch?

Hi,

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

Output:

 Store pointer for procedure func
 now in func 
 Store pointer for procedure sub
 now in sub

 

 

0 Kudos
3 Replies
Highlighted
Black Belt
232 Views

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.

0 Kudos
Highlighted
232 Views

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.

Jim Dempsey

0 Kudos
Highlighted
Valued Contributor III
232 Views

minervanl wrote:

..  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 ..

@minervanl,

As mentioned upthread, you can get the compiler to issue errors and warnings by turning on appropriate compile-time options:

https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-warn

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.

0 Kudos