Page 1 of 1

Operands priority

Posted: Wed Jan 19, 2005 8:23 pm
by Psychophanta

Code: Select all

a.l=$aabbcc
e.l=$ffeedd
Debug Hex($FFFF&e|a)
Debug Hex(e|a&$FFFF)
Why I get different values?
Shouldn't be the same?
Bug?

Posted: Wed Jan 19, 2005 8:35 pm
by Pupil
It seems the binary operators '&' and '|' have the same priority so i assume they just evaluate from left to right, the shift operators('<<' and '>>') however seems to have higher priority than the previously mentioned operators and are thus evaluated first..

Posted: Wed Jan 19, 2005 10:58 pm
by Psychophanta
Pupil wrote:It seems the binary operators '&' and '|' have the same priority so i assume they just evaluate from left to right, the shift operators('<<' and '>>') however seems to have higher priority than the previously mentioned operators and are thus evaluated first..
But operators should NEVER be evaluated by position in expressions, but by type.
That's an ultra-BIG bug 8O

Posted: Wed Jan 19, 2005 11:00 pm
by Psychophanta
Admin: Please move this Subject to Bug Reports section. :arrow:

Posted: Wed Jan 19, 2005 11:08 pm
by Saboteur
But I think you have same problem in C. You must use parenthesis to avoid this. Or what do you want to evaluate first?

Posted: Thu Jan 20, 2005 12:02 am
by Pupil
Psychophanta wrote:
Pupil wrote:It seems the binary operators '&' and '|' have the same priority so i assume they just evaluate from left to right, the shift operators('<<' and '>>') however seems to have higher priority than the previously mentioned operators and are thus evaluated first..
But operators should NEVER be evaluated by position in expressions, but by type.
That's an ultra-BIG bug 8O
I think they behave in a logical way, i.e. as i expected them to evaluate, one thing i'm missing though, is a complete list in the manual of the priority order of the operators.

Posted: Thu Jan 20, 2005 10:33 am
by Psychophanta
Saboteur wrote:But I think you have same problem in C. You must use parenthesis to avoid this. Or what do you want to evaluate first?
Same problem in C ?? Mmm... I'm not sure. If you say that...I didn't know it. However, i think AND operator should have priority over OR operator for logical expressions, and at least in the old Borland C++ there is like that.
Pupil wrote:one thing i'm missing though, is a complete list in the manual of the priority order of the operators.
Yes! Me too. :x

Posted: Sat Jan 22, 2005 12:47 pm
by blueznl
hey psycho, i think the and should have priority above the or... actually, it doesn't matter, as long as it is properly documented!

Posted: Sat Jan 22, 2005 3:31 pm
by Blade
There are common rules, just like * is higher than +
If any language would start using its own priorities, would be a big mess...

Posted: Sun Jan 23, 2005 7:22 pm
by Psychophanta
Blade wrote:There are common rules, just like * is higher than +
If any language would start using its own priorities, would be a big mess...
Agree. :)

Posted: Sun Jan 23, 2005 9:53 pm
by Psychophanta
blueznl wrote:hey psycho, i think the and should have priority above the or... actually, it doesn't matter, as long as it is properly documented!
Well, yes, i think you're right, corrected my above post :oops: