www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Second article about some bugs

The second article about common bugs in C/C++ (and probably sometimes D too)
code (I have shown the first link here some time ago), it's nice because it
shows real world bugs:

The Reddit thread:

On Reddig one person (LittlemanTAMU) says:
What's more productive, whining about a language's design choices that cannot
now be changed or pointing out common errors with real world examples so the
people that have to use the language can write better code?<
My answer is something like: thankfully new languages are being developed, so some troubles/bugs are avoidable. The article shows probable bugs like: void main() { enum uint BAR = 0b011; int foo = 10; auto x = !foo & BAR; } The comments of their static analysis tool is something like:
V564 The '&' operator is applied to bool type value. You've probably forgotten
to include parentheses or intended to use the '&&' operator.<
------------------- Another class of bugs shown is of the kind: int Z = X + (A == B) ? 1 : 2; Meant to be: int Z = X + (A == B ? 1 : 2); But in reality is this, because of the low priority of the ternary operator: int Z = (X + (A == B)) ? 1 : 2; Bye, bearophile
Apr 04 2011