[Issue 4077] Bugs caused by bitwise operator precedence

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 10 20:32:35 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4077


Adam D. Ruppe <destructionator at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator at gmail.com


--- Comment #3 from Adam D. Ruppe <destructionator at gmail.com> 2010-04-10 20:32:33 PDT ---
Yeah, when it bit me today, I wasn't thinking about it at all. The code looked
like this:

assert( a|b <= max);

I meant (a|b) <= max, but the code ended up being a|(b <= max), which was
fairly useless.

I don't think bitwise being lower than comparison is useful, but we have the
difficulty here of maintaining C compatibility. The best fix we can get, if one
is really needed*, is to call it an error to have a bitwise operation next to
anything that trumps it, unless parenthesis are present.

The error brings instant attention to the trouble spot, and adding explicit
parens is no big trouble - I, and surely many others, usually do this by habit
anyway - so I'd be happy with this solution.

* (this is he only time I can recall being bitten by this in all my years of
writing C and friends, so it really isn't a big deal to me)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list