3 ms·
Three notes: 1. The SafeInt class helps detecting integer overflows: http://safeint.codeplex.com/ http://safeint.codeplex.com/ Also, most SafeInt binary oper
by danieldk 15y ago
Three notes:
1. The SafeInt class helps detecting integer overflows:
http://safeint.codeplex.com/ http://safeint.codeplex.com/
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!
- dazzawazza 15y agofor 3 clang will (by default report): 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.
- pagekalisedown 15y ago3: I've rarely seen "Yoda conditions" [1] in the wild. I think it's because most compilers will output a warning when doing an assignment inside an if statement. [1] http://www.dodgycoder.net/2011/11/yoda-conditions-pokemon-exception.html http://www.dodgycoder.net/2011/11/yoda-conditions-pokemon-ex...
- wglb 15y agoBe sure that you have the fixed version: http://blog.regehr.org/archives/593 http://blog.regehr.org/archives/593 as there were errors in the previous.