- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have encountered a behavior I don't understand...
My code looks like this:
program aa
use module xx
...
a1=fun(x,y,1)
a2=fun(x,y,0)
...
end program aa
module xx
function fun(x,y,i)
...
end function
subroutine G()
...
a1=fun(x,y,1)
a2=fun(x,y,0)
...
end subroutine G
end module xx
Now when I call fun(x,y,1) and fun(x,y,0) from the program aa it gives two different results and puts it correctly into variables a1 and a2.
When I call fun(x,y,1) from subroutine G (which is in the same module as fun) BOTH a1 and a2 changes to the result of fun(x,y,1) and then when I call fun(x,y,0) again both a1 and a2 changes into result of fun(x,y,0). So a1 and a2 have the same value, which is what I really don't want them to.
It seems to me that a1 and a2 (in the module) point into the memory where the actual result of fun is present.
Why are there different behaviors in these two situations?
How can I avoid such behavior?
My code looks like this:
program aa
use module xx
...
a1=fun(x,y,1)
a2=fun(x,y,0)
...
end program aa
module xx
function fun(x,y,i)
...
end function
subroutine G()
...
a1=fun(x,y,1)
a2=fun(x,y,0)
...
end subroutine G
end module xx
Now when I call fun(x,y,1) and fun(x,y,0) from the program aa it gives two different results and puts it correctly into variables a1 and a2.
When I call fun(x,y,1) from subroutine G (which is in the same module as fun) BOTH a1 and a2 changes to the result of fun(x,y,1) and then when I call fun(x,y,0) again both a1 and a2 changes into result of fun(x,y,0). So a1 and a2 have the same value, which is what I really don't want them to.
It seems to me that a1 and a2 (in the module) point into the memory where the actual result of fun is present.
Why are there different behaviors in these two situations?
How can I avoid such behavior?
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page