jswaff wrote:
A bit sloppy?? It is a "best practice" to minimize the scope of variables.
It improves readability, and more importantly, limits visibility of the variable. True, in C, you *have* to declare local variables at the head of the block, but that is definitely a habit worth breaking.
Actually, you don't have to do that in C.
The 1999 C standard added a number of useful features, such as specified size data types (uint64_t, for example) along with // comments, complex numbers, and the ability to specify local variables where ever you need to, including within a for (...) statement.
Quite a few interesting additions over C89.
The problem is, even after 9 years, many compilers *still* don't support the current C version.
C just isn't "sexy" any more, so vendors just don't care as much as they do about C++.
I'll admit that many of the things in C99 aren't absolute requirements. But some of them sure are nice. Things like uint64_t for example. And knowing you can legally do // comments. And even localized local vars like this discussion is about.
Personally, I think that if your compiler can't handle a 9 year old C standard (or at least attempts to support many of the simpler additions), then it's time to find a compiler that does.
If you are forced to stay with C89, a 19 year old standard, then you might as well go back one more year and stay with K&R C...
(Or use Small-C.... That was kind of fun to program in.)