A lot of messages about UNION! I'll try to give a general answer.
The name is really not important, except if it is misleading. I agree
with Steven Lionel that translate and convert are bad names. I haven't
thought that they could suggest a modification of the bit pattern. I am
still unhappy with TRANSFER() because it could suggest that something is
moved. I disagree here with Bill Long. Maybe the right word is "cast"
(as used in the C terminology). Note: a = TRANSFER(b...) implies copying
memory, but this in not because of TRANSFER(). Cfr. a = c, which also
implies copying memory.
OK: TRANSFER() is syntactically a function. Unfortunately the following
is _not_ possible:
! code 1
type(t1) :: a
call toto(transfer(a, ..))
...
subroutine toto(b)
type(t2), intent(out) :: b
Well, my opinion is that the standard could have permitted it. In this
case TRANSFER() would not be a _normal_ function. This should be
functionally equivalent to
! code 2
type(t1) :: a
type(t2) :: temp
call toto(temp)
a = transfer(temp, ..)
I have used temp just to explained the effect of the code. A good
compiler should optimize the temp code out. In this sense code 2 is a
replacement for code 1. This could be an answer to Michel Olagnon, who
gave an example with READ.
At this point I tend to believe that TRANSFER could be used to rewrite
code containing EQUIVALENCE. Instead of using aliases for the same piece
of memory, the same variable name (say a) should be used. Following
constructs can be used
Assignments:
(1) a = transfer(b, ..)
(2) b = transfer(a, ..)
Calls:
(3) call toto(transfer(a, ..)) ! in argument
(4) call titi(temp) ! out argument
a = transfer(temp, a, ..)
I think a good compiler should be able to treat TRANSFER as a casting
operator and to optimize out the temp computation. No one has said
anything about what the real world compilers do. :-(
I hope I haven't missed the point of the whole discussion, which was a
bit complicated. Cheers, Vittorio
-------------------------------------------------
Dr. Vittorio G. Caffa Tel.: (089) 6088-2054
IABG, Abt. AF 11 Fax: (089) 6088-3990
Einsteinstr. 20 E-Mail: [log in to unmask]
D-85521 Ottobrunn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|