This toy code has a problem. The program needs an explicit interface for the subroutine print_i
.
module types
type plain
integer :: i
end type plain
type, extends(plain) :: fancy
integer :: i2
end type fancy
end module
program poly
use types
! UH-OH! Missing interface!
type(plain) :: pl
type(fancy) :: fan
pl%i = 10
fan%i = 20
call print_i(pl)
call print_i(fan)
end program
subroutine print_i(instr)
use types
class(plain) :: instr
print '("i is ",i5)', instr%i
end subroutine
When I try to compile with GNU Fortran, it won’t compile, and gfortran complains about the missing interface. What is strange to my mind is that Intel Fortran compiles an executable without complaining, but then it dies with a seg fault in print_i
. When I put the interface in …
interface
subroutine print_i(instr)
use types
class(plain) :: instr
end subroutine
end interface
both compilers compile without error and their executables run fine.
The Intel behavior seems strange to me. Why not flag something that can’t run? Any ideas?
(BTW, I understand that I can put print_i
into the module and have simpler code. But this came up because of something I am trying to test.)