0

I would like to use the generic name of a function to overload the '*' operator as in the example below:

interface scala
    module procedure :: scalapr,scalarp
end interface scala
interface operator(*)
   module procedure :: scala
end interface operator(*)

However, compiling with gfortran, I get:

Error: Procedure 'scala' in intrinsic '*' operator at (1) is neither function nor subroutine

Is there any turn-around ?

1 Answer 1

2

You must overload with the specific function

interface scala
    module procedure :: scalapr,scalarp
end interface scala
interface operator(*)
   module procedure :: scalapr, scalarp
end interface operator(*)

The generic is not a module procedure, so it cannot appear in module procedure.

There is also just procedure, but that won't help here. It is for procedures not coming form the current module. But anyway, the functions in the generic interface block must be specific functions.

See Fortran 2008 12.4.3.4 Generic interfaces:

1 A generic interface block specifies a generic interface for each of the procedures in the interface block. The PROCEDURE statement lists procedure pointers, external procedures, dummy procedures, or module procedures that have this generic interface. ...

According to 7.1.6:

5 A function defines the binary operation x1 op x2 if
  (2) either
     (a)  a generic interface (12.4.3.2) provides the function with a generic-spec of OPERATOR (op),
  or
     (b)  there is a generic binding (4.5.5) in the declared type 

so the rules above do apply as does the constraint

C1207 (R1206) A procedure-name shall be a nonintrinsic procedure that has an explicit interface.

A generic-name does not conform to C1207.

Sign up to request clarification or add additional context in comments.

2 Comments

That was clear from the compiler message. My question was if there is any alternative.
Nope, there isn't. That's what I am saying. (You would be surprised how many people here don't read or don't try to understand compiler messages.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.