- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Given a pointer variable within a routine declaration that is initialized to null, does that imply the save attribute?
For example, the following implies SAVE in the variable mxval and nullifies tmp.
Since I don't nullify tmp at the exit of the subroutine, does it retain its pointer association despite the null() on line 4:
subroutine set_pnt(pnt, val)
integer, pointer:: pnt
integer:: val
integer, pointer:: tmp => null()
integer:: mxval = 99
!
allocate(tmp, source=val)
pnt => tmp
!
end subroutine
To me it would seem better to have the first line in the subroutine say
nullify(tmp)
to remove the implied SAVE.
Or is SAVE only implied for non-pointer variables?
Also, is tmp is auto-disassociated when the subroutine exits or is that behavior not guaranteed?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no restriction on an initialized variable being pointer, it is SAVEd (unless in a COMMON block). On reentry to the routine, it will have whatever association it had on the last exit. Since your first action is to allocate tmp, I don't see a point in initializing it. Otherwise, I would do away with the initialization and add the explicit nullify.
If tmp did not have the SAVE attribute, then on exit its association status becomes undefined (it is not nullified.) It would also be undefined on entry.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page