Beware though that this was banned in C89, so a strictly conforming
compiler would barf on it.
I'm pretty sure you are incorrect in this (I briefly checked my copy of
On 15 Apr 2003 05:05:37 +0200
Anders Johansson wrote:
the standard). It is perfectly legal in C89 to define a variable within
a block, whether that block in the block.
In K&R (traditional) the initializing of an automatic variable was
generally illegal (depending on the compiler). C89 explicitly made this
legal:
if (condition) {
int i = 0;
};
However, I don't always initialize automatic variables.
if (condition) {
int i = 0;
for(i=0; i < 10;i++) {
}
};
In this case, the initialization of i is redundant. But, it is also a
common mistake for programmers to fail to initialize automatic variables
before they are used, which can have many consequences.
--
Jerry Feldman
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9