madoflancashire
madoflancashire

Reputation: 51

Overload arrow operator (=>) in fortran

I just started overloading operators (including assignment) in Fortran 2003, and I want to overload the arrow operator (=>) for my user-defined type. I know for most operators, like (+), I would say

interface operator(+)  
    ! What I want this to mean instead  
end interface operator

But, that doesn't work for (=>). I know for assignment, I would say

interface assignment(=)  
    ! What I want this to mean instead  
end interface assignment

which still doesn't work for (=>).

Specifically, I define a type where the underlying data is a pointer.

type my_type
    integer, pointer :: data(:)
end type my_type

So, when I say

type (my_type) :: a
integer, target :: b(4)

! Do stuff to b
a => b

I'd like this to mean

a%data => b

Thank you for any suggestions! Answers in standards other than the 2003 standard will also be helpful.

Upvotes: 3

Views: 595

Answers (1)

francescalus
francescalus

Reputation: 32406

It is not possible to overload pointer assignment in Fortran 2018.

This question asks about using type-bound procedures to approach the overloading, but in the more general sense the answer is still no.

Up to Fortran 2018, the meaning of a pointer assignment statement

a => b

is always to affect the pointer status of the pointer a on the left-hand side.

Although the Fortran standard has intrinsic and defined assignment (this latter introduced with interface assignment(=)), there is no such distinction for pointer assignment.

Upvotes: 1

Related Questions