generics - Fortran 运算符

标签 generics fortran operator-keyword

我正在使用 ^ 实现两个向量的叉积,但是 我收到一个错误。不知道如何解决这个问题。

这是代码

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

这是我在使用 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)

最佳答案

我相信该标准排除了使用任意符号的可能性,例如 ^ , 在定义运算符时。在2008年的标准草案中我必须交出第7.1.6.1.4段的状态

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.

定义的二进制操作是停止之间的字母序列,例如 .cross..times. , 而内在运算符是语言标准中定义的运算符之一( +<* 等)。

由@francescalus 提出,我应该补充一点,序列不应超过 63 个字母,并且不应与任何内部运算符(例如 .eq)或逻辑文字(例如 .true.)相同

关于generics - Fortran 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26493695/

相关文章:

c - 如何在 C 中读取 fortran 二进制文件?

java - 比较 VS <?扩展比较>

json - Swift - 无法使用泛型转换类型的值

vim - ctags 和 Fortran 的接口(interface)

c++ - 在运算符重载参数列表中包含 const 会产生错误 (C++)

c++ - 为什么编译器说我不能将项目插入到 std::set<Item> 中?

c# - 定义两个可为 null 的隐式运算符时无法将 null 转换为 struct

Java 泛型比较器单例

c# - 在线程之间传递 List<Polyline>

Fortran READ(*,*), WRITE(*,*) 参数