I'm looking through some old Fortran 90 code and have come across the =>
symbol:
var => item
It looks like it's being used for some sort of assignment.
Searching Google for "arrow symbol Fortran" or "equals greater than symbol Fortran" gives me no related material.
=>
appears in six contexts as a syntactic element in modern Fortran, many, but not all, related to pointers: pointer assignment; pointer initialization; procedure (pointer) declaration; type-bound procedure declaration; association; renaming. There is close connection between most of these. Loosely, in many=>
can be viewed as providing an alternative temporary or permanent means of referencing another entity. In none, however, is=>
acting as an operator.1Pointer assignment
Pointer assignment is one of the traditional appearances of
=>
, appearing in Fortran 90. It is used to associate a pointer with a target, and is explained in another answer.Use association renaming
Renaming of entities use associated involves the element
=>
and is the other appearance in Fortran 90/95 code. Suchuse
statements are likeFollowing such a
use
statement the module entitiesa
andbb
are known by the local namesc
andcc
.Pointer initialization
Pointer initialization is much like pointer assignment where
=>
appears. Pointer initialization defines the initial pointer association of the pointer. We see this in statements such asWith this explicit initializtion, the pointer
b
here is initially associated witha
and the pointerc
is initially unassociated. These two forms are helpful in modern Fortran in that in Fortran 90 a pointer always starts life initially of undefined association status. Here we know thatb
andc
have defined pointer association status, and we can useASSOCIATED
.For derived type components such syntax gives default initialization.
Procedure declaration
Much as with explicit/default initialization for data objects
=>
features in defining the initial association of a procedure pointer.Here,
proc1
is again initially associated with the proceduredonkey
and we can have such things asmuch as we could when
proc1
is pointer assigned withdonkey
outside the declaration statement.proc2
is, as expected, initially not associated.As with data object components of derived types
=>
can feature in setting the initial association of an object-bound procedureType-bound procedure declaration
Conceptually related to the above is the use of
=>
in declaring type-bound procedures.Here in the type
a
proc
is a binding name so thatb%proc
(forb
an entity of typea
) is a procedure reference. We also, throughtype_a_eq
, have defined assignment with entities of typea
on the left-hand side.Association
=>
appears in three association contexts. Theassociate
,select type
andselect rank
constructs associate a name with a selector.From Fortran 2003 we have
and
Introduced in (the current draft of) Fortran 2018 we have
These associations differ from pointers.
a
in theassociate
block needn't be (and in the example above isn't) a variable.[1] The concept of operator is precisely defined in the Fortran language, such as in 3.2.4 of the Fortran 2008 specification. Unlike many other languages, assignment (with
=
) itself is not an operation, but a statement. In C-like languages we can have(a=b)
as an expression returning a result: this is not the case in Fortran. The same holds for pointer assignment in Fortran. The other cases above are wholly distinct from this idea of assignment. In Fortran, even=
appearing in initialization is not the same thing as assignment.=>
cannot be viewed as having one effect.Surprisingly, searching "equals arrow symbol Fortran" yields some results.
"=>" is commonly referred to as the pointer assignment operator.
(Though it is not truly an operator as it returns no value.)
It is used to associate a chosen reference name with a target:
The above can be read as "reference refers to target"
Most often this reference occurs in the form of a pointer. In this case you could say "reference points to target". This is a helpful way to remember what this operator does as its literal appearance is of an arrow pointing from reference to target.
Further Uses
Additional uses including making local aliases for various items such as module components, procedures, and even arbitrary expressions. For a full explanation of all of these uses see this answer.
Pointer assignment vs. Traditional Assignment (=)
Here's a quick example from the above link that illustrates how pointer assignment differs from classic assignment ("="). Basically this shows that once a target has been established, the pointer is treated as that target for basic statements.
Other Resources:
General documentation on Fortran pointers