Fixes for compiling under C89 mode

* Move for-loop declarations to top of methods
* Use C89-style comments
* Additionally fix a few signedness issues

This also fixes compilation for me under VS2013.