I would like to know if the following code may ever fail with the access violation or if it’s safe. Is the first member of the statement with AND operator always checked as first or may be (by some compiler optimization or something) checked the second one as first ?
var
Item: TSomething;
procedure DoSomething;
begin
if Assigned(Item) and (Item.SomeProperty) then
DoSomethingElse;
end;
Is the code above definitely safe ?
Thanks!
The code is safe given boolean short-circuit evaluation is active:
It is a bit confusing as the
B(orBOOLEVALwith long name) directive must be turned OFF to switch short-circuit evaluation ON…See also Operator Precedence.