Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

function results?

meistrv
Beginner
372 Views
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?
0 Kudos
0 Replies
Reply