Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array section

Status
Not open for further replies.

shredzone

Programmer
Jan 30, 2007
4
0
0
CA
This is an elementary question that has been bugging me since sometime. If I pass an array section to a subroutine that declares the corresponding dummy array explicitly would there be a physical copy of the object (assuming the interface of the callee is available to the caller)? Is there an advantage of passing a pointer instead (I am new to Fortran pointers)?
 
Fortran parameters are passed by location-value. This is not the same as call by value - there is no local copy. It passes the address of the parameter to the routine.

There are two types of pointers in Fortran: there are pointers and there are Cray pointers.

First Pointers - these can be considered as aliases for variables and arrays. There is no advantage in passing pointers other than maintenance. For instance
Code:
! without pointers
x = a(3) * a(3)
a(3) = a(3) + 1
!
! with pointers
aptr => a(3)
x = aptr * aptr
aptr = aptr + 1
No real difference in the code until it comes to maintenance. If you wanted to use a(5) instead of a(3), it would be a one line change in the pointer version.

Pointers can be used like arrays with no upper bound so if you need to pass a section; that is not the same as passing a pointer.

Cray pointers are like the ones in C and all other languages. They do not have to be of any specific type and can point anywhere in memory including illegal places. They're useful for stuff like shared memory and if anyone wants still does it, pointing to memory mapped devices.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top