fix ISO C90 forbids mixed declarations and code [-Werror=declaration-aft...

reorder declaration and statement to fix the error of "ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]" for some versions of gcc