CBFalconer said:
Now there I'll argue. It protects against compilers that have
fouled up the reinitialization of such a statement, and only uses
constructs that must be well tested.
Proper initialization of objects declared within blocks is not some
obscure construct that a compiler writer is likely to get wrong. In
fact, the body of a function definition (the part enclosed by '{' and
'}') is syntactically nothing more than a compound statement.
Nothing dangerous about
that.
It's your attitude ("Too lazy to back up your claims, but not to lazy
to make them in the first place") that I find dangerous. (Quoting
myself, not you.)
And I see no point in searching through the standard for
something that backs or fails to back my C90 contention, especially
since I don't even have a C90 standard.
So look it up in K&R, either edition. Or check the plain-text
pre-ANSI draft at <
http://flash-gordon.me.uk/ansi.c.txt>, which says:
| 3.6.2 Compound statement, or block
|
| Syntax
|
| compound-statement:
| { declaration-list<opt> statement-list<opt> }
|
| declaration-list:
| declaration
| declaration-list declaration
|
| statement-list:
| statement
| statement-list statement
|
| Semantics
|
| A compound statement (also called a block )allows a set of
| statements to be grouped into one syntactic unit, which may have its
| own set of declarations and initializations (as discussed in
| $3.1.2.4). The initializers of objects that have automatic storage
| duration are evaluated and the values are stored in the objects in the
| order their declarators appear in the translation unit.
I admit I don't know of any compilers so fouled. However I could
see myself making such a mistake, so I want to protect against it.
Someone implementing a compiler presumably would bother to read the
standard, or at least K&R.
This correspondence is not really progressive, since it
basically an argument over preferences.
If you *prefer* to put all declarations in the outer block of a
function, that's ok; I'd simply disagree and move on. But you haven't
been stating it as just a preference. You've been defending it with
arguments that are quite simply factually incorrect.