[Issue 4077] Bugs caused by bitwise operator precedence

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 12 06:09:52 PDT 2010


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


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #6 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-04-12 06:09:47 PDT ---
(In reply to comment #1)
> Care to quantify 'frequent'?  Just because something can cause a bug doesn't
> make it a disaster.  I can't recall ever making a bit wise precedence error
> myself.  Of course, that too isn't proof of anything.

I run into this all the time.  It makes me absolutely paranoid about bitops to
where I sometimes write things like:

if((a | b))

or

a = (b | c);

Before I realize the extra parens don't do much :)

If you write routines that parse protocols or use bitfield flags, you will run
into this bug.

I always wondered why bitwise operators were lower in precedence than
comparison, but you just learn to accept it (and judiciously use parentheses
around such things).  If D could make strides to help solve this problem, I
think it would be great.  Probably not earth shattering, but just another
feather in the cap.  When someone writes something like:

if(a | b == c)

I'd say it's always an error.  Not even almost always, but always.  If D could
flag this as such, it would be a good thing.  I strongly feel, however, that
bitwise ops should simply have a higher precedent than comparison, since the
current behavior is always an error.  You will not find any C code that looks
like this on purpose.  I don't see any reason to keep the current
interpretation regardless.

-- 
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