Re: DO loop standards question.
From: Richard Maine (nospam_at_see.signature)
Date: 02/03/04
- Next message: Richard Maine: "Re: Is this standard f90?"
- Previous message: Claus Pedersen: "Re: Size of Largest Array?"
- In reply to: James Cownie: "Re: DO loop standards question."
- Next in thread: Michel OLAGNON: "Re: DO loop standards question."
- Reply: Michel OLAGNON: "Re: DO loop standards question."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 03 Feb 2004 08:45:55 -0800
James Cownie <jcownie@etnus.com> writes:
> Do you believe that _any_ do loop which has an iteration
> count of more than most positive representable value of the
> integer type of the control variable is non-conforming ?
Yes...I think, though that one is more subtle than your original
question.
In your original sample, the standard specifies that when the
loop terminates the DO variable has a value larger than the most
positive reprsentable value for its kind. That is pretty
explicitly invalid (each kind has a set of valid values - this
isn't one of them).
Your new question hinges on the kind used in the computation of the
iteration count. The wording about this in the f90 standard is a bit
indirect; it is more explicit in f95 (might even have been an f90
interp that prompted the more explicit wording - I forget). Anyway,
the initial value, final value, and incrementation value are specified
(quite explicitly in f95) to be the same type and kind as the DO
variable. The standard says that the iteration count is computed
and gives a formula using those 3 values. That formula would
overflow if the iteration count was too large for the kind.
On the other hand, I suppose one could interpret the formula as
a mathematical one instead of a computational one. The kind of
the values used in the formula is explicitly specified, but I
find myself uncertain as to whether to interpret the formula as
a mathematical or computational one. That's the subtlety.
Wouldn't surprise me if some compilers might compute the iteration
count using a default integer, allowing it to work. Of course, that
would then get them in "trouble" is someone was doing loops with
integers larger than default.
But I'd be leary.
I'd be *VERY* leary of loops whose iteration count exceeded the
largest positive default integer. I'd be willing to bet that
some compilers will have problems with that (possibly including
symptoms like making the loop infinite).
-- Richard Maine | Good judgment comes from experience; email: my first.last at org.domain | experience comes from bad judgment. org: nasa, domain: gov | -- Mark Twain
- Next message: Richard Maine: "Re: Is this standard f90?"
- Previous message: Claus Pedersen: "Re: Size of Largest Array?"
- In reply to: James Cownie: "Re: DO loop standards question."
- Next in thread: Michel OLAGNON: "Re: DO loop standards question."
- Reply: Michel OLAGNON: "Re: DO loop standards question."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|