Deep array copy in Fortran

Viewed 15779

I need a deep copy of a (real) array in Fortran (90), but am not sure exactly how to get one, since I do not completely understand how references work. Intuitively, I would expect this to get me what I want:

do i=1,n
  b(i) = a(i)
end do

However, it was recently pointed out to me that b(1:n) = a(1:n) is equivalent to the code above. Intuitively, I would expect that b(1:n) = a(1:n) merely causes the reference of b(1:n) to point to the location of a(1:n) in memory.

Is b(1:n) = a(1:n) a deep copy? Why? What is going on with the underlying references as opposed to b = a?

2 Answers
Related