[fpc-pascal] Boolean expression short-circuit
Kornel Kisielewicz
charon at magma-net.pl
Tue Nov 22 15:43:11 CET 2005
Ok, I've been arguing over that with a friend of mine for a couple of
e-mail's now... I need your help!
Let me show an example first:
type TFoo = class end;
var Foo : TFoo;
The question is, wether this is valid:
if (Foo <> nil) and (Foo.inheritsFrom(TFoo)) then do_something;
I would have no questions about that (first the Foo is checked, so
inheritsFrom is called ONLY if Foo <> nil) if it weren't for the
statement in the manual:
<quote>
Remark: The order in which expressions of the same precedence are
evaluated is not guaranteed to be leftto-right. In general, no
assumptions on which expression is evaluated first should be made in
such a case. The compiler will decide which expression to evaluate first
based on optimization rules.
</quote>
Can I make the assumption that boolean expressions are GUARANTEED to be
evaluated left-to-right?
regards, and thank you,
--
At your service,
Kornel Kisielewicz [http://chaos.magma-net.pl/doom]
"Some thing's just cannot be programmed in a roguelike. For
everything else, there's GenRogue" -- Anubis
More information about the fpc-pascal
mailing list