Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Transfer and variables that don't use all their storage space.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
James Giles  
View profile  
 More options Apr 9 2007, 12:42 am
Newsgroups: comp.lang.fortran
From: "James Giles" <jamesgi...@worldnet.att.net>
Date: Mon, 09 Apr 2007 04:42:18 GMT
Local: Mon, Apr 9 2007 12:42 am
Subject: Re: Transfer and variables that don't use all their storage space.

Richard Maine wrote:
> James Giles <jamesgi...@worldnet.att.net> wrote:
...
>> The internal representation of ALLOCATABLE components
>> of a derived type would almost certainly be very similar to the
>> internal representation of a POINTER component....
>> What TRANSFER would
>> operate on would be the implementation dependent bits of
>> such a hidden descriptor.

> Yes, that's what I would expect. *HOWEVER*, if you transfer the bits
> of such a descriptor that is allocated, you are likely to end up with
> two different allocated allocatables trying to use the same storage.
> That is certainly not envisioned and is likely to cause havoc. A
> straightforward reading of the words that Brooks cited above seems to
> suggest that it ought to work, since the resulting variable is
> claimed to have the same value as the original. That's the kind of
> situation I'm envisioning, and I think the cited words of the
> standard completely fall apart for cases like that.

> Yes, I can imagine what I'd expect to happen in practice, based on
> transfer just copying the bits, and I can imagine people trying to
> take advantage of that for system-dependent stuff. No debate there.
> I'm talking purely about standard-conforming code, and code that the
> standard claims ought to be portable as well by the above citation.

There are a lot of things that can cause havoc.  I think the committee
probably envisioned that abuse of TRANSFER would cause havoc.
Everything about TRANSFER is implementation dependent.  So, its
not even possible to discuss the havoc (except speculatively) without
stating what implementation you're talking about.  The semantics of
TRANSFER are defined in terms of *representations* and not
*values*.  The fact that the resulting *values* are meaningless (the
LOGICAL result transferred from INTEGER, for example) or even
dangerous (multiple ALLOCATABLE components associated with
the same storage) is the programmer's responsibility.

Still, I don't see the ALLOCATABLE components problem as all
that bad.  The result of TRANSFER must be assigned or it's lost.
(OK, it could also be an actual argument to a procedure, and maybe
there are other uses I can't think of on an Easter night.  But let's
consider
the obvious first.)  So, suppose you do:

   var = transfer(transfer(E, D), E)

Where E and VAR are both some derived type and D is some type
big enough to hold all the bits of the derived type.  In this case, the
ALLOCATABLE components of VAR do *not* end up associated
with the same storage as the components of E.  This is because of
the semantics of assignment.  It has nothing to do with TRANSFER
at all.  It's the same result as if you had written var = E.  It may be
that the other cases, such as passing the result of TRANSFER as an
actual argument to a procedure, turn out to be equally benign.  You
would have to go through each possibility carefully.  If they aren't
all benign, well that's one of the kinds of havoc.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."   --  C. A. R. Hoare


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.