program main
complex :: z
real, dimension(2) :: cmp
z = (1.0, 2.0)
cmp = 4.0
cmp = transfer(z, cmp, 1) * 8.0
if (cmp(1) .ne. 8.0 .or. cmp(2) .ne. 4.0) print *,"unequal"
end program main
I suspect it isn't standard-conforming, because the size is too short
for cmp, but I'd like to be sure.
> Is the following program standard-conforming...
>
> program main
> complex :: z
> real, dimension(2) :: cmp
> z = (1.0, 2.0)
> cmp = 4.0
> cmp = transfer(z, cmp, 1) * 8.0
> if (cmp(1) .ne. 8.0 .or. cmp(2) .ne. 4.0) print *,"unequal"
> end program main
>
> I suspect it isn't standard-conforming, because the size is too short
> for cmp, but I'd like to be sure.
It is not conforming (and this anything may happen). I guess I'm
surprised that you aren't sure. I suspect that the complications of
TRANSFER are just distracting you from the simple part, which you did
mention. The details of the exact value of the TRANFER result don't
matter; all you need to know, as you allude to, is that the result is a
rank 1 array of size 1. So the question reduces to one of whether
cmp = x
is valid when cmp is an array of size 2 and x is an array of size 1. It
isn't. Shape must match in arra-to-array assignments. Why would you even
think otherwise? Are you perhaps thinking about the fact that
cmp = 4.0
is valid with 4.0 being scalar? If so, it is important to remember that
an array of size 1 is *NOT* the same thing as a scalar.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
A minor change that makes it standard-conforming is in line 6:
cmp(1:1) = transfer(z, cmp, 1) * 8.0
and then it prints nothing.
--
John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington, New Zealand
e-mail john....@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045