#96 if statement not evaluated left to right

closed-fixed
nobody
5
2013-05-25
2001-07-21
Michael Hope
No

As per support/regression/tests/logic.c:

/* Test that the evaluation is aborted on the
first hit. */
if (false || true || neverGetHere()) {
/* Tested using neverGetHere() */
}

/* Test that the evaluation is aborted on the
first false. */
if (true && false && neverGetHere()) {
/* Tested using neverGetHere() */
}

where 'true' is a variable which is not zero, and
'false' is a variable which is zero.

I believe that an if should be evaluated left to
right, with the evaluation aborting as soon as the
the outcome is known. In the first, it should abort
as soon as 'true' is evaluated and never evaluate
neverGetHere. In the second, it should abort as soon
as 'false' is evaluated.

Turns out that it's also broken in another way. In
evaluating, it resolves down to just a call to
neverGetHere - no testing of 'true' or 'false'.

Discussion

  • Johan Knol
    Johan Knol
    2001-10-23

    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Johan Knol
    Johan Knol
    2001-10-23

    Logged In: YES
    user_id=63512

    fixed in SDCCast.c:1.93

    This only happended with an emty if body. Now it is tested
    for side effects (++ and () )