Operands priority
Posted: Wed Jan 19, 2005 8:23 pm
Code: Select all
a.l=$aabbcc
e.l=$ffeedd
Debug Hex($FFFF&e|a)
Debug Hex(e|a&$FFFF)Shouldn't be the same?
Bug?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
a.l=$aabbcc
e.l=$ffeedd
Debug Hex($FFFF&e|a)
Debug Hex(e|a&$FFFF)But operators should NEVER be evaluated by position in expressions, but by type.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..
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.Psychophanta wrote:But operators should NEVER be evaluated by position in expressions, but by type.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..
That's an ultra-BIG bug 8O
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.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?
Yes! Me too.Pupil wrote:one thing i'm missing though, is a complete list in the manual of the priority order of the operators.
Agree.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...
Well, yes, i think you're right, corrected my above postblueznl 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!