When trying to overload subprograms using common interfaces or combining modules or procedures associated with type binding, you must consider that any of the procedures with the same common name must have distinguishable or incompatible arguments.
When using unlimited polymorphic objects, you can quickly run problems like this in this incredible tutorial:
INTERFACE foobar SUBROUTINE foo(x) INTEGER :: x END SUBROUTINE foo SUBROUTINE bar(x) CLASS(*) :: x END SUBROUTINE bar END INTERFACE foobar
Here foo(x) conflicts with bar(x) , since the argument bar can also be INTEGER .
This particular problem can be solved with the SELECT TYPE construct in a new routine that replaces the common interface:
SUBROUTINE foobar(x) CLASS(*) :: x SELECT TYPE (x) TYPE IS INTEGER CALL foo(x) CLASS default CALL bar(x) END SELECT END SUBROUTINE foobar
However, sometimes such designs can become tedious and undesirable.
Are there other ways to implement this specialization without using the SELECT TYPE construct?
fortran
kvantour
source share