Re: Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)
From: James Giles (jamesgiles_at_worldnet.att.net)
Date: 01/17/05
- Next message: Another Jake: "Re: Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- Previous message: beliavsky_at_aol.com: "Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- In reply to: beliavsky_at_aol.com: "Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- Next in thread: Another Jake: "Re: Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 17 Jan 2005 03:01:04 GMT
beliavsky@aol.com wrote:
> Roy Smith wrote (in comp.lang.python):
>
>> Believe it or not, in some early versions of Fortran, numbers were not
>
>> immutable! I forget the exact scenario, but if you did something like:
>
>> subroutine munge (i)
>> i = 3
>> return
>
>> and then in your main program did:
>
>
>> j = 7
>> call munge (7)
>> write (6, 11) j
>> 11 format ('j = ', i6)
>
>> it would print 3! The problem is that numerical constants were interned
>> (i.e. in the main program, there was only a single 7 stored in memory,
...
> Was this (the ability to redefine the value of '7') ever really true of
> Fortran, or a particular Fortran compilers?
This was always illegal. In the FORTRAN 66 standard document
it says (§8.3.2):
If an actual argument corresponds to a dummy argument that is
defined or redefined in the referenced subprogram, the actual
argument must be a variable name, an array element name, or
an array name. [...]
All Fortran standards have required that actual arguments be
definable if they are associated with dummy arguments that
change during the execution of the procedure. It is not, however,
a violation that's required to be detected or reported by compliant
implementations. So, programs that violate the requirement are
subject to arbitrary treatment by the implementation - including
starting WWIII, but more often , the above mentioned strange
behavior.
I've long advocated that if the actual argument is a not definable,
an anonymous copy should be created that is associated with
the dummy argument. The procedure could then change it as
desired. The anonymous copy is then ignored upon return.
This is the behavior required for dummy arguments that have
the VALUE attribute in the F2003 standard. But the rule I just
stated would give the control to the caller of the procedure.
-- 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
- Next message: Another Jake: "Re: Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- Previous message: beliavsky_at_aol.com: "Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- In reply to: beliavsky_at_aol.com: "Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- Next in thread: Another Jake: "Re: Redefining a numeric constant in Fortran (Was Re: why are some types immutable?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|