Why does the Fortran 90 Specification specify (5.2.8) that the TARGET keyword must be used to associate a POINTER to it? Why isn't every type a valid TARGET?
For example,
is valid syntax but
INTEGER, POINTER :: px
INTEGER, TARGET :: x
x = 5
px => x
is not valid.
INTEGER, POINTER :: px
INTEGER :: x
x = 5
px => x
Why must this be?
A target is another normal variable, with space set aside for it. A target variable must be declared with the target attribute. You associate a pointer variable with a target variable using the association operator (=>).
Pointers are a new feature to the Fortran standard and bring Fortran 90 into line with languages like C. The use of pointers can provide: A flexible alternative to allocatable arrays. The tools to create and manipulate dynamic data structures (such as linked lists).
The POINTER attribute designates objects as pointer variables. The term pointer refers to objects with the Fortran 90 POINTER attribute.
The Pointer in C, is a variable that stores address of another variable. A pointer can also be used to refer to another pointer function. A pointer can be incremented/decremented, i.e., to point to the next/ previous memory location. The purpose of pointer is to save memory space and achieve faster execution time.
An item that might be pointed to could be aliased to another item, and the compiler must allow for this. Items without the target attribute should not be aliased and the compiler can make assumptions based on this and therefore produce more efficient code.
Pointers in fortran are different than pointers in c. In fortran 90 pointers were provided with few restriction like having a target. This was done to address speed issue and to keep pointer usage safe. Although one call make allocatable pointers which do not need to specify a target. Dig deeper and you will find them!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With