Eight C++ programming mistakes the compiler won’t catch
pixelstech.net
pixelstech.net
1. The SafeInt class helps detecting integer overflows:
Also, most SafeInt binary operators do not allow for mixing of SafeInts for different integer types.
2. Valgrind helps with detecting use of uninitialized memory.
3. A (rather ugly) solution to prevent accidental use of = rather than == when a constant expression is used, is to make the constant expression the first operand. E.g.:
if (0 = x) // fail! Using the result of an assignment as a condition without parentheses
Place parentheses around the assignment to silence this warning
Use '==' to turn this assignment into an equality comparison
this can be turned off though.[1] http://www.dodgycoder.net/2011/11/yoda-conditions-pokemon-ex...
C++ is not different - it can even provide you with even more interesting and unexpected ways to shoot yourself in the foot:
C++ (from: http://m5p.com/~pravn/foot.html)
You accidentally create a dozen instances of yourself
and shoot them all in the foot.
Providing emergency medical care is impossible since
you can't tell which are bitwise copies and which are
just pointing at others and saying, "That's me over there."