Alexei Matveev asked:
>Can anybody explain me what should happen
>after assignment
> x = y
>if the typed variables declared as:
>
>type :: TYP
> real,pointer :: p(:)
> real,allocatable :: a(:)
>end type
>
>type(TYP) :: x,y
>
>call allocate_and_place_some_data(y)
>
> x = y
Yes, pointer components get "shallow copied" and allocatable components
get "deep copied".
The assignment "x = y" is equivalent to:
! Shallow assign pointer components
x%p => y%p
! Deep assign allocatable components
if (allocated(x%a)) deallocate(x%a)
if (allocated(y%a)) then
allocate(x%a(lbound(y%a,1):ubound(y%a,1)))
x%a = y%a
end if
You probably don't want to mix pointer and allocatable in the same type
like this. It could lead to confusion...
Cheers,
--
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
([log in to unmask])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|