As was mentioned in the READONBLY thread pointers in F2000 will
can have an INTENT() attribute. What are the proposed rules?
I can think of three possible versions:
INTENT(IN OUT) and INTENT(OUT) I think are not controversial at all.
But INTENT(IN) allows several rules:
a) pointer status cannot be changed
i.e., nullify, deallocate, another target are not allowed
but the value of the target can be changed (if it exists)
b) the value of the target cannot be changed
but the pointer can be pointed elsewhere
c) neither can the pointer be pointed elsewhere
nor can the value of the target be changed
I personally prefer c) because it is the easiest and clearest version
though maybe too restrictive for others, while a) and b) have a
non-intuitive flavour.
Maybe we need a more detailed INTENT version for pointers?
One can certainly start with c) and relax later if that is needed.
NOTE that rule c) is NOT equivalent to passing to a non-pointer dummy
as this example shows:
With c) rule:
subroutine foo_c( x )
real, pointer, intent(in) :: x
...
end subroutine foo_c
With a non-pointer dummy:
subroutine foo_d( x )
real, intent(in) :: x
...
end subroutine foo_d
because one cannot check the association status of x in foo_c.
A more useful example is a standard dynamic data structure as
this queue (I coded this recently, that's why I am keen to know):
type, private :: queue_node
type(data) :: dat
type(queue_node), pointer :: next
end type queue_node
type :: queue
private
type(queue_node), pointer :: front, rear
end type queue
! object-based style version of a queue, if you like
function isEmpty( q ) result( Empty )
type(queue), pointer :: q
logical :: Empty
if( .not.associated(q) ) then
Empty = .true.
else
Empty = .not.associated(q%front)
end if
return
end function isEmpty
Here I could use (for safety, clarity) an INTENT(IN) for q where rule c)
seems most appropriate though a) is possible. But a) would allow to
allocate q%front, for example.
Cheers,
WWS
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|