> In article
news.nems.noaa.gov>,
> Paul Van Delst noaa.gov> writes:
>> Steven G. Kargl wrote:
>>> In article
news.nems.noaa.gov>,
>>> Paul Van Delst noaa.gov> writes:
>>>
>>>>>
>>>>> The following two line, I believe, are nonconforming.
>>>>
>>>> Really? Huh... I can't be bothered hunting through the standard so
>>>> I'll take your word for it (I have used equivalence about two times
>>>> in the last 20 years I reckon so I have no idea as to how to use it
>>>> in a standard-ly manner.)
>>>
>>>
>>> You need to wade through Section 14 of the Fortran 95 standard.
>>>
>>>
>>>
14.7.6 Events that cause variables to become undefined
>>>
>>> Variables become undefined as follows:
>>> (1) When a variable of a given type becomes defined, all associated
>>> variables of different type become undefined. However, when a
>>> variable of type default real is partially associated with a
>>> variable of type default complex, the complex variable does not
>>> become undefined when the real variable becomes defined and the
>>> real variable does not become undefined when the complex variable
>>> becomes defined. When a variable of type default complex is
>>> partially associated with another variable of type default complex,
>>> definition of one does not cause the other to become undefined.
>>>
>>> Your read statement caused the double precision variable to become
>>> defined. Thereby, i3 is technically undefined. The Standard does
>>> not list this as a constraint, so a compiler can do anything it
>>> wants. This includes the de facto standard of simply using i3 'as if'
>>> had been defined.
>>
>> I read the standard in the section you indicated and, pardon my
>> denseness, but how is an equivalence statement ever to be used
>> to equivalence different types? Or have you never been able to do
>> that?
>
> We're going to need someone like Richard Maine to comment on the
> historical developement of equivalence.
>
>> In
14.7.5 (Events that cause variables to become defined) it states that:
>>
>> (10) When a character storage unit becomes defined, all associated
>> character storage units become defined. When a numeric storage
>> unit becomes defined, all associated numeric storage units of
>> the *same type* [my emphasis] become defined. When an entity of
>> double precision real type becomes defined, all totally associated
>> entities of double precision real type become defined. When an
>> unspecified storage unit becomes defined, all associated unspecified
>> storage units become defined.
>>
>> Fair enough. Associated storage unit of same type == everything gets
>> defined. But the standard also allows equivalencing of different types,
>> and of scalars and arrays.
>
> AFAICT, equivalance of different types is simply storage association
> where different variables can re-use memory. Back when 64 KB of memory
> was considered standard. Re-using memory was very important.
>
>> So, for the case of different types in an equivalence, whenever you
>> define one you automatically undefine the other?
>
> Yep. I believe the idiom would be
>
>> That is,
>> integer :: i
>> real :: x
>> equivalence (i, x)
>> i=10 ! This causes x to become undefined
>
> Do a bunch of computations involving i where x isn't needed.
>
>> x=1.0 ! Whoa. This causes i to become undefined
>
> Now, do a bunch of computations with x where i isn't needed.
>>
>> Wha..?
>>
>> I'm missing something obvious here.
>
> Probably just the 60 year history of a language where memory
> went from ? -> 16 KB -> 64 KB -> 640 KB -> 16 MB -> 4 GB -> 16 GB.
Undefined means that you can not predict the value and as far as the
standard is concerned you should lot even consider looking at the value.
Consider moving from a machine with sign magnitude integers and reals
to one with sign magnitude reals and twos complement integers. Ask whether
the interpretation of a bit pattern is the same in both places. If no then
you see the practical effects of "undefined".
If you have an integer and a real equivalenced do you really expect the
value of the integer stashed in some register by the optimization to
be updated because the associated real gets assigned into. Nope! You
should not be in a position where you might want that value, which should
be a dead variable anyway.
In the bad old days of game playing under F66 such equivalences were one
way of looking at the bit configuration of a real, or taking several
cahracters out of a packed word, etc. All nonconforming and totally
reliant on the whims of the compiler of the day.