William F Mitchell asked:
>Does the standard address what should happen when the SOURCE in a TRANSFER
>call is a derived type with a POINTER component?
Not really, though the intent is (I think) as you describe.
In general though, I'd advise against using TRANSFER unless you really need it.
That doesn't seem to be the case here.
TRANSFER does tend to confuse both users and implementors. It also doesn't
tend to be particularly efficient.
>Second question: I cannot use the usual INQUIRE approach to find out how big
>the integer array needs to be (see the commented-out code above) because an
>"output list item" cannot contain a derived type object that ultimately
>contains a pointer component. Are there any other ideas on how to portably
>determine how big the array has to be?
Note that INQUIRE does not give you any useful information about the array size
needed for TRANSFER, except by accident. It gives you the values for RECL=.
You wrote:
>s = 12
>it(1:s) = transfer(t,0,s)
Instead, do
S = SIZE(TRANSFER(T,IT))
IT(:S) = TRANSFER(T,IT)
>For the curious, the point of this exercise is to transfer a structure into an
>array of integers which then gets passed to a C function. The C function DOES
>NOT use it; it just passes it on to another Fortran subroutine, which will use
>TRANSFER to recover the original structure.
Well, this does more than that - it makes a "copy" of the derived type.
I don't know whether you *want* that - maybe you do?
If you just want to pass the derived type argument through, you can probably
just pass the variable itself (receiving it into a C "void *" pointer). That
works with all the compilers I'm familiar enough with, including our own - we
don't do anything funky with derived type arguments.
If you want to pass a copy, you could pass "TRANSFER(T,(/0/))" without
assigning it to a variable. Or even easier, just have another TYPE(MYTYPE)
variable T_COPY, assign T to T_COPY and pass T_COPY.
Cheers,
--
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
([log in to unmask])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|