Silverfrost Forums

Welcome to our forums

Abstract Interface

18 Dec 2025 10:23 #32567

Is it easy to get FTN95 to support ABSTRACT INTERFACE? Blame ChatGPT for the request - it is making some suggestions to 'improve' my code! I have just had it help me solve a long-term ClearWin+ problem so I'm giving it a bit more credibility than I would have done a little while back.

19 Dec 2025 7:41 #32568

'abstract interface' is already supported, at least in some contexts.

See for example \Program Files (x86)\Silverfrost\FTN95\source64\clrwin.f95.

Please let us know if there are valid contexts where it is not supported.

19 Dec 2025 10:24 #32569

Here is an example, which Gfortran 13.4 accepts:

MODULE abstr_int
implicit none

ABSTRACT INTERFACE
   function fun_2_args(x, y)
integer,parameter:: dp=kind(0.d0)
   real(dp) :: fun_2_args
   real(dp), intent(in) :: x, y
   end function fun_2_args
END INTERFACE

INTERFACE
   module function fun1(x,y)
integer,parameter:: dp=kind(0.d0)
    real(dp) :: fun1
   real(dp), intent(in) :: x, y
   end function fun1
!***
   module function fun2(x,y)
integer,parameter:: dp=kind(0.d0)
   real(dp) :: fun2
   real(dp), intent(in) :: x, y
   end function fun2
END INTERFACE
END MODULE abstr_int

For this code, FTN95 says: ERROR S:\absi.F90 13: MODULE cannot appear in a INTERFACE block

19 Dec 2025 12:35 #32570

mecej4

Thank you for the feedback. I have logged this for investigation.

20 Dec 2025 7:21 #32579

It is great to see Abstract Interface available. I did find one problem. In the program below, FTN95 compiles with an error message stating that cbf0 is undefined. The error message goes away if Only is not used.

! FTN95 does not recognise cbf0, but does if Only is removed
Module m1
   Public :: cbf0
   Abstract Interface
      Integer Function cbf0()
      End Function cbf0
   End Interface
End Module m1
Module m2
   Use m1, Only: cbf0
Contains 
   Integer Function cbf( f1 )
      Procedure(cbf0) :: f1
   End Function cbf
End Module m2
20 Dec 2025 7:44 #32580

mecej4

I suspect that MODULE FUNCTIONs are only meaningful when used with SUBMODULEs. At the moment FTN95 does not support SUBMODULEs and this is likely to be a significant undertaking (given the intrinsic complexity of MODULEs). Maybe something for 2026.

simon

Thank you for the bug report. It appears that at the moment you can't USE an ABSTRACT INTERFACE it has to be copyied to the place where it is used.

29 Dec 2025 8:13 #32616

This missing feature has now been added for the next release of FTN95. In the mean time you may be able to use a more primative form like

integer, external::foo

as in

Module m1
   Public :: cbf0
   Abstract Interface
      Integer Function cbf0()
      End Function cbf0
   End Interface
End Module m1

Module m2
   Use m1, Only: cbf0
Contains
   Integer Function cbf( f1 )
   Procedure(cbf0) :: f1
    cbf = f1()
   End Function cbf
End Module m2

integer function foo()
  foo = 42
end function foo

program main
use m2
!>>>procedure(cbf0)::foo
integer,external::foo
kk = cbf(foo)
if(kk ==42) print*, 'Success'
end program

In this context PROCEDURE is essentially the same as EXTERNAL but with added type checking for the arguments of the function.

Please login to reply.