Prevent a number of warnings under g++.

Unused variables, out-of-order initializations, signed/unsigned comparisons.