Message-ID: <[log in to unmask]>
Priority: NORMAL
X-Mailer: Execmail for Win32 5.1.1 Build (10)
MIME-Version: 1.0
Content-Type: Text/Plain; charset="us-ascii"
On Mon, 21 Oct 2002 08:37:09 -0500 Kurt W Hirchert
<[log in to unmask]> wrote:
> At 08:57 AM 10/21/2002 -0400, Tom Clune wrote:
> > From these results I infer that the code is, in fact, not standard
> >conforming, and I should have declared the integer "i" in routine
> >sub_init(). In fact, once I have done so, I get the same answer
> >(7938) under all of the above compilers. (Well, the default
> >options for Cray Cf90 still give 26, but I suspect that a compiler
> >bug is involved here.) Apparentl, I was just "unfortunate" enough
> >to be developing under the one compiler that gave the intended
> >answer even with the illegal code.
>
i've been bitten by this type of problem (using the wrong instance of a
variable) a few times when using pascal. the first time was on the
advisory desk at imperial college. there were several nested functions.
the inner most function had access to all of the variables in the
surrounding routines. it took a couple of days to finally spot
where the problem was.
whilst in this case it is clearly an error (altering a do loop variable)
maybe the compiler could give a warning about a potential problem in
the more general case.
mind you the pascal compilers didn't :-)
> 1. Without the declaration, the code is not standard conforming because the
> recursive call to sub_init changes the value of i, and such changes to the
> DO variable are not allowed inside a DO loop. Differences in the extent to
> which the compilers used the assumption that i was unchanged can explain
> most, if not all, of the differences in behavior by the different compilers.
>
> 2. If the DO loop is converted to an equivalent DO WHILE loop (which has no
> concept of a DO variable and thus no restriction on changing that
> variable), the program is standard conforming without the declaration. The
> "correct" answer in this case appears to be the one the MIPSpro compiler
> gave for the DO loop version -- 111. (This, of course, is not the answer
> you wanted, but it is the "correct" reflection of your inadvertent logic
> error in using a shared i instead of separate copies of i for each instance
> of sub_init). I would hope that all of the compilers would give the 111
> answer for the DO WHILE version of the program.
> -Kurt
>
> In case anyone wonders what I mean by the equivalent DO WHILE loop, I converted
> Do i = 1, N_CHILDREN
> ...
> End Do
> to
> i=1
> Do While (i <= N_CHILDREN)
> ...
> i = i + 1
> End Do
> If run with a local declaration of i, this gives the 7938 answer Tom
> expected. If run with only the host declaration, it gives the 111 answer.
>
> --
> Kurt W Hirchert [log in to unmask]
> UIUC Department of Atmospheric Sciences +1-217-265-0327
--
Ian
[log in to unmask]
Home page
http://www.kcl.ac.uk/kis/support/cit//fortran/
comp-fortran-90 home page
http://www.jiscmail.ac.uk/lists/comp-fortran-90.html
|