Functions returning pointers
Paul Brook
paul@codesourcery.com
Sun Aug 22 20:44:00 GMT 2004
On Sunday 22 August 2004 21:29, Tobias Schlüter wrote:
> Paul Brook wrote:
> >>Am I right in assuming that this program should print "2 2"?
> >> integer, pointer :: p
> >> integer, target :: t
> >> t = 1
> >> p = f()
> >
> > Presumably should be "p => f()"
> > Works file with that change :)
> >
> :-O (getting red, tries to save himself by diverting attention) Well it
> : looks like I found a quality of implementation issue -- shouldn't that
> code segfault?
Now I think about it a bit more, there is another way of "fixing" your code:
integer, pointer :: p
integer, target :: t
t = 1
allocate (p) !!!!!!
p = f()
p = p+1
print *, t, p
contains
function f()
integer, pointer :: f
f => t
end function f
end
This does show a gfortran bug, though possibly not the one you were originally
trying to demonstrate ;-)
Paul
More information about the Fortran
mailing list