BrogueCE icon indicating copy to clipboard operation
BrogueCE copied to clipboard

Another Priority Issue of && and II

Open drwjf opened this issue 2 years ago • 0 comments

There is a compiler warning in Items.c

boolean polymorph(creature *monst) {
   ...
    if (monst->creatureState == MONSTER_FLEEING
        && (monst->info.flags & (MONST_MAINTAINS_DISTANCE | MONST_FLEES_NEAR_DEATH)) || (monst->info.abilityFlags & MA_HIT_STEAL_FLEE)) {
 ...

Place parentheses around the '&&' expression to silence this warning

Based on the compiler default priority, the code is equal to

    if ((monst->creatureState == MONSTER_FLEEING && (monst->info.flags & (MONST_MAINTAINS_DISTANCE | MONST_FLEES_NEAR_DEATH)))
       || (monst->info.abilityFlags & MA_HIT_STEAL_FLEE)) {

But I thought it should be

    if (monst->creatureState == MONSTER_FLEEING
        && ((monst->info.flags & (MONST_MAINTAINS_DISTANCE | MONST_FLEES_NEAR_DEATH)) 
                || (monst->info.abilityFlags & MA_HIT_STEAL_FLEE))) {
 ...

Is this a bug?

drwjf avatar Dec 24 '22 07:12 drwjf