Board index » delphi » Delphi 2 buggy ?

Delphi 2 buggy ?

Anybody explain whats going on here ?

for I := 1 TO Ntp do
  for J := 1 TO 30 do
  begin
    x:=lres[I,J];
    if x > 100 then
       break;       {end of data marker}
    writeln(fout,Actout:5:2,',  ',Lres[I,J]:5:2);
  end;
end;

a) No code is generated for the 'break' command and so the routine runs past
the end of data marker.

b) putting a watch on J reveals that the 'J' loop is counting down from 30
to 1 instead of up (although the output from the routine is correct).

c) Turning optimization off makes the routine do something different but
doesn't fix it.

d) changing the 'break' command to
     begin
         writeln(' ');
         break
     end;
     makes the routine work !

What the hell is going on ?

Any help appreciated.

Andy K

 

Re:Delphi 2 buggy ?


Quote
Lucifer wrote:

> Anybody explain whats going on here ?

> for I := 1 TO Ntp do
>   for J := 1 TO 30 do
>   begin
>     x:=lres[I,J];
>     if x > 100 then
>        break;       {end of data marker}
>     writeln(fout,Actout:5:2,',  ',Lres[I,J]:5:2);
>   end;
> end;

> a) No code is generated for the 'break' command and so the routine runs past
> the end of data marker.

I would not advise using break when optimisations are on in nested for
loops. It's not always clear what is going to happen.

Quote
> b) putting a watch on J reveals that the 'J' loop is counting down from 30
> to 1 instead of up (although the output from the routine is correct).

That's fine, that's a standard optimisation.

Quote
> c) Turning optimization off makes the routine do something different but
> doesn't fix it.

> What the hell is going on ?

Possibly an optimisation bug. Anyway, I tend to avoid using break as
much as possible... it has a habit of not liking optimisers.

MH.

--
Martin Harvey.
Totally rewritten web pages at:
http://www.harvey27.demon.co.uk/mch24/

"ALGOL 60 was a language so far ahead of its time that it
was not only an improvement on its predecessors but also
on nearly all its successors". C.A.R. Hoare

--------------BEGIN GEEK CODE BLOCK--------------
Version: 3.12
GCS/CC d(+) s-:- a-- C+++$ UL@ P L@>++ E- W++
N+++ o-- K++ w+++$ O--- M-- V-- PS@ Y-- PGP-
t--- 5-- X-- R-- !tv b+ DI+ D+ G e++ h- r z++>---
---------------END GEEK CODE BLOCK---------------

Other Threads