The bug is in your code, not in the optimiser (actually turning the
optimiser on or off makes no difference).

The correct code is:

  for n := 0 to Count - 1 do
    if CheckAccount(Items[n]) or result;
 
Short circuit evaluation is part of the delphi specs (and part of the
specs for about every language except vb).  Basically any boolean
evaluation will return as soon as the answer is known.  Turning this off
will break vast amounts of code including the vcl.

It lets you do nice things like
  if assigned(foo) and foo.IsChanged then
    foo.SaveChanges;

The answer is not to change the compiler settings but to change your
code:).

Regards

Sean
---------------------------------------
Sean Cross
mailto:[EMAIL PROTECTED]

Pics Print - The photo printing solution for Windows. 
http://www.picsprint.com

Rental Property Manager: Rental management made easy
http://www.Intuitex.com
 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Wilfried Mestdagh
> Sent: 17 November 2005 7:52 a.m.
> To: Delphi-Talk Discussion List
> Subject: Re[2]: strange optimization bug?
> 
> 
> Hello Sid,
> 
> >    for n := 0 to Count - 1 do
> >      if CheckAccount(Items[n]) then result := true;
> 
> Yes correct, but I just liked the 'or' :)
> 
> > short-circuit evaluation
> 
> This is probably my english, but this is for me not a short 
> circuit evaluation. eg this is:
>   if a and b and c
> if a already evaluate false then dont check the rest. That is 
> partial expression check or short circuit, but maybe it is my 
> English...
> 
> > Although it is possible to turn off short-circuit 
> evaluation as others 
> > suggested, I find that at least for the programs that I write 
> > (compute-intensive vs. user interaction intensive), there is a 
> > difference in performance
> 
> Yes but you can set it off for the needed lines of code and 
> back on. I tryed this (D7) to be sure of it, because there 
> are a lot of situations that with turning it off you can get 
> a lot of exceptions not wanted if you count on it...
> 
> ---
> Rgds, Wilfried
> http://www.mestdagh.biz
> 
> __________________________________________________
> Delphi-Talk mailing list -> [email protected] 
> http://www.elists.org/mailman/listinfo/delphi-> talk
> 
> 


__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to