3

I am implementing the cross product of two vectors using ^, however I am getting an error.Not aware how the problem can be resolved.

Here is the code

Interface Operator (^)
    Module Procedure vector_cross_product
End Interface Operator (^)

Contains

Function vector_cross_product (u, v) Result (w)

    !!$ Input
    Type (Vector), Intent(in) :: u, v

    !!$ Output
    Type (Vector) :: w

    w% x = (u% y * v% z) - (u% z * v% y)
    w% y = (u% z * v% x) - (u% x * v% z)
    w% z = (u% x * v% y) - (u% y * v% x)

End Function vector_cross_product

This is the corresponding errer I am getting using gfortran

Interface Operator (^)
                    1
Error: Syntax error in generic specification at (1)
lib/vectors.f:110.18:

  Module Procedure vector_cross_product
                  1
Error: MODULE PROCEDURE at (1) must be in a generic module interface
lib/vectors.f:111.3:

End Interface Operator (^)
   1
Error: Expecting END MODULE statement at (1)
1
  • There are reasons for these restrictions. They are not going away with Fortran 2015 and I cannot really see them going away before the fixed source form. Commented Oct 23, 2014 at 7:22

1 Answer 1

5

I believe that the standard rules out the use of arbitrary symbols, such as ^, when defining operators. In the draft of the 2008 standard I have to hand para 7.1.6.1.4 states

A binary defined operation is an operation that has the form x1 defined-binary-op x2 or x1 intrinsic-operator x2 and that is defined by a function and a generic interface.

A defined-binary-op is a sequence of letters between stops, for example .cross. or .times., and an intrinsic-operator is one of the operators defined in the language standard (+, <, *, etc).

Prodded by @francescalus, I should add that the sequence should be no longer than 63 letters and should not be the same as any of the intrinsic operators (e.g. .eq) or logical literals (e.g. .true.)

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

1 Comment

[That sequence defined by R723 in 7.1.2.8.]

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.