Newsgroups: comp.lang.fortran
From: nos...@see.signature (Richard Maine)
Date: Sun, 8 Apr 2007 18:39:43 -0700
Local: Sun, Apr 8 2007 9:39 pm
Subject: Re: Transfer and variables that don't use all their storage space.
Brooks Moses <bmoses-nos...@cits1.stanford.edu> wrote: Edge cases of TRANSFER are a mess. I'm convinced the standard is > I'm working on implementing compile-time handling of the transfer > intrinsic for GFortran, and have a couple of edge-case questions about > the standard that I'm hoping someone here can comment on. inconsistent about some of them. Anyway... > The Fortran 2003 standard states that TRANSFER(TRANSFER(E,D),E) should That's one part I'm sure is inconsistent. That can't realistically be > result in E, if D and E are scalar variables and the physical > representation of D is as long as or longer than that of E. (Section > 13.7.121, lines 30-32.) expected to work in all cases. I think that whoever wrote those words just didn't think of the edge cases at all. Consider a scalar of a type that has allocatable components (perhaps multiple of them, at multiple depths). I really don't think that the standard envisions going through and doing all the allocations that would be needed to make that work; and I sure don't know what the intermediate bits would be. That's without even thinking of issues like hardware locations that just > Now, consider a processor which supports 4-byte LOGICAL and INTEGER I think I agree with that. I'm not sure what is naive about it. It is > variables, and suppose that D is a LOGICAL and E is an INTEGER. > Further, suppose that the canonical representations of 4-byte logicals > in this processor are to flip the 1-bit to either 1 or 0, and leave the > rest zero. > A naive reading of the double-transfer requirement would claim that, if pretty explicit that all transfer does is copy bits - not convert them. The bit that you quoted about transfer(transfer(e,d),e) is more of an elaboration of what you'd expect (in simple cases) to result from transfering the bits. I think it belongs as a note instead of as normative text. (And it probably should be corrected with qualifications, even as a note.) > I would contend that this reading is incorrect -- that, in particular, I agree, except with your comment that the para before is incorrect. > if E has a bit representation that is not one of the canonical bit > representations for a logical variable, then the inner transfer > statement is illegal according to the comments in the beginning of > section 13.7 which state that a program is not allowed to invoke an > intrinsic with arguments that produce out-of-range results. And further > that the double-transfer identity requirement obviously is only meant to > apply when both transfer calls, taken independently, are legal. These two paras don't seem inconsistent to me. I think *BOTH* of them are right. The first para describes what the standard requires to happen (that the bits just get copied without change). The second para correctly (in my view) notes that this requires disallowed behavior in some cases. I agree with the conclusion that the code is illegal on machines where the resulting bit pattern is an invalid one. > Further, a strictly literal reading of the beginning of section 13.7 I don't see that. As mentioned above, the essential definition of > would suggest that when transferring a value to a real number, NaN > should be returned if the bit representation is not a legal real number. TRANSFER is that is just copies the bits. I don't think it ever does any kind of manipulation of them, such as normalizing, generating NaNs or anything of the sort. You just get the bits as is. If those bits aren't valid for any reason, then the code is illegal. Note that assignment can do things like normalize, so the result of somevariable = transfer(something,somevariable) might end up with somevariable being normalized, even though the -- 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.
| ||||||||||||||