[Issue 4077] Bugs caused by bitwise operator precedence
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 10 19:54:29 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4077
--- Comment #2 from bearophile_hugs at eml.cc 2010-04-10 19:54:25 PDT ---
>Care to quantify 'frequent'?<
I'd like to, but finding hard statical data about bugs is hard. Often you just
have to use your programming experience and memory of past mistakes. I have
programming experience, and for the last years I am writing down all my bugs.
You can ask the GCC developers what kind of statical data they have used to
decide to recently introduce that warning into gcc. I think they have no
reliable statistical data. But they are usually smart people, so you can't just
ignore their example.
>Just because something can cause a bug doesn't make it a disaster.<
Just because something can't cause disasters but just bugs doesn't justify
ignoring it. And sometimes silent bugs like this one actually cause disasters.
>I can't recall ever making a bit wise precedence error myself. Of course, that too isn't proof of anything.<
I have done several of similar bugs. Later I have taken the habit of always
putting parentheses around shift and bitwise ops, if they are compound with
other things.
That post on the D newsgroup shows Adam Ruppe too once has done this bug.
See the -Wparentheses here:
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
It says several interesting things. It also says:
>Warn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about.<
They say "often get confused about".
That warning switch also warns against probably wrong code like (this is
another common source of bugs that's missing in Python):
if (a)
if (b)
foo ();
else
bar ();
--
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