Re: Do loops until HUGE?



In article
<4PQIe.552451$cg1.405193@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"James Giles" <jamesgiles@xxxxxxxxxxxxxxxx> wrote:

> The trip count is computed in this case as:
>
> trips = huge(i) - huge(i) +10 + 1
>
> And that's 11. The compiler is free to assume that the
> value returned by HUGE(i) is the same for both calls
> without even making use of that value.

Indeed. But the compiler is also free to do a lot of other things,
some of which involve exceeding limits and thus making the program
invalid. The compiler *MAY* compute it as above, and that might even be
a preferred way. But it isn't required. Expressions that are
mathematically equivalent are allowed, even if they are computationally
different. Overflowing is a computational difference.

And regardless of how the trip count is computed, if the value of the
loop variable ends up as one that exceeds the compiler's representable
range, then the code is illegal. WWIII is unlikely as a result, but
messing up the DO loop trip count is plausible, within the allowed
things a compiler may do with such illegal code, and happens in some
actual compilers.

So I think that the end result is still

1. You can't assume this will work with all compilers. (It won't).

2. You can't use the standard to beat vendors into making it work.

--
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

  • Re: Do loops until HUGE?
    ... But the compiler is also free to do a lot of other things, ... > mathematically equivalent are allowed, ... the standard explicitly says that the trip count for a do ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: Typical/common?
    ... snip ... ... great for creating portability problems and are all too easy to ... trip up on - having a function called "index" is perfectly ... reasonable to me and I don't like it when my compiler with default ...
    (comp.arch.embedded)
  • Re: OT: Different types of counting in loops
    ... Mostly it seems that the extensions were in places that you really ... only for variables as the compiler would refuse it for constants. ... trip through the loop method. ...
    (comp.lang.fortran)
  • Re: Inlining of C# functions
    ... > Can anybody tell me if the C# compiler will automatically inline simple ... trip through ILDasm with a bit of code that does it and see. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: MR&C 7.9
    ... using illegal code, ... compilers, or perhaps even on the same compiler with different options. ... In some cases it will be set to zero as you observed. ... because you observe some behavior in one case, ...
    (comp.lang.fortran)