Well, add this one too, as it is also related I think:
You should be able to create two independent
modules that are duplicates of each other except for type and not have
them collide if both overload the names. So adding the
INTERFACE lines in each module lets you use both modules.
That is, overloading is a legitimate way to create generic interfaces without
the modules having to know about each others existence unless used in the same scope. And then they will coexist unless they conflict “automatically”.
So declaring all public procedure names in rather redundant-looking
interfaces they can be used with other modules using the same names without renaming as
long as they are distinguishable from one another.
This is what happened automatically with one compiler in the past and accidentally became a “feature” I was using, but now to get that behavior
you have to add the overload syntax.
Using USE with ONLY clauses and renaming things is probably a better
practice, but this use of overloading can make it very easy to generate modules supporting
different types by using INCLUDE and cpp directives judicially.
Anyway, this should be legal and is related to the previous issue:
open wab2 in Fortran Playground
Fortran source
click to see more...
module A
implicit none
interface rabbit; module procedure rabbit; end interface rabbit
contains
subroutine rabbit(value)
integer :: value
value=value+1
end subroutine rabbit
end module A
module B
implicit none
interface rabbit; module procedure rabbit; end interface rabbit
contains
subroutine rabbit(value)
real :: value
value=value*value
end subroutine rabbit
end module B
module gestalt
use A, only : rabbit
use B, only : rabbit
end module gestalt
program demo_duplicates
use A, only : rabbit
use B, only : rabbit
real :: x
integer ::i
x=4.4
i=5
write(*,*)x
call rabbit(x)
write(*,*)x
write(*,*)i
call rabbit(i)
write(*,*)i
end program demo_duplicates
Output
click to see more...
+aoccflang520 : 2 4.400000
+aoccflang520 : 3 19.36000
+aoccflang520 : 4 5
+aoccflang520 : 5 6
+flangtrunk : 2 4.4
+flangtrunk : 3 19.36
+flangtrunk : 4 5
+flangtrunk : 5 6
+ifxlatest : 2 4.400000
+ifxlatest : 3 19.36000
+ifxlatest : 4 5
+ifxlatest : 5 6
+ifxlatest_standard : 2 4.400000
+ifxlatest_standard : 3 19.36000
+ifxlatest_standard : 4 5
+ifxlatest_standard : 5 6
+++ cexpl -c lfortranlatest --skip-asm '--cflags=--fixed-form-infer --no-style-suggestions --realloc-lhs-arrays --print-leading-space --std f23 --use-loop-variable-after-loop --cpp -DCOMPILER_=lfortranlatest' wab2.f90
=lfortranlatest : 3 semantic error: Arguments do not match for any generic procedure, rabbit
-lfortranlatest : 4 --> /app/example.f90:33:4
-lfortranlatest : 5 |
-lfortranlatest : 6 33 | call rabbit(x)
-lfortranlatest : 7 | ^^^^^^^^^^^^^^
+nvfortran_x86_26_3 : 2 4.400000
+nvfortran_x86_26_3 : 3 19.36000
+nvfortran_x86_26_3 : 4 5
+nvfortran_x86_26_3 : 5 6
+gfortran161 : 2 4.40000010
+gfortran161 : 3 19.3600006
+gfortran161 : 4 5
+gfortran161 : 5 6
If wishes were fishes …
If Lfortran were built into Discourse so you could just click on the code snippets
and run them locally that would be nice.