Re: DO loop standards question.

From: Richard Maine (nospam_at_see.signature)
Date: 02/03/04


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


Relevant Pages

  • Yow! LOOP macros are LOOPY!
    ... By relying entirely on procedure calls to express iteration, ... to but cleaner than C's FOR loop. ... other macros going around at the time other than MacLisp's ... (bind (vi (vector-ref v i))) ...
    (comp.lang.scheme)
  • Re: Polling, Interrupts, DMA, Synchronous, Asynchronous I/O Definitions
    ... the terminology is less useful than it might be. ... though a "message loop" could arguably be claimed to be ... considering in a particular iteration but what is true for _ALL_ ... watching the "polling" version eating up every single CPU cycle ...
    (alt.lang.asm)
  • Re: Histogram of character frequencies
    ... generated object code may simply be a loop in which elements are ... believe any C compiler anywhere would reject it. ... On the first iteration of the loop you test the end of file indicator ...
    (comp.lang.c)
  • Re: Random number help
    ... is used to generate cooccurance matrix for each iteration of for loop. ... disp('the sample co-occurance matrix is as follows');% GIVING SAME ...
    (comp.soft-sys.matlab)
  • Re: LOOP blows!
    ... The order of initialization follows the ... There are two `initializations' in execution of LOOP, ... before staring the first iteration. ... |> The first for clause will never terminate. ...
    (comp.lang.lisp)