Fixes for more cppcheck issues (v2 of #101)

These commits address issues like:
- use static_cast instead of C-Style cast
- remove unused variables
- perform initialization of variables in initialization list of constructor
- use %u to format unsigned in snprintf()
- remove never executed statements after return
- reduce scope of some variables
- catch exception by reference
- prefer prefix ++/--operator for non-primitive types

v2 of pull request #101