Topic: for containing declaration
Author: David R Tribble <david@tribble.com>
Date: 2000/03/24 Raw View
[news:comp.std.c++ added. -drt]
"Douglas A. Gwyn" wrote:
>
> David R Tribble wrote:
>> The question still stands, though: Are these ill-formed in C?
>> C++98 goes to the trouble of spelling this case out explicitly; C99
>> doesn't.
>
> There is nothing wrong with them in C99. I don't know why C++98
> went out of its way to outlaw them. (Presumably it has something
> to do with destructors, but I don't see a problem.)
Probably it was because C++ has an extra sticky notion of scope in a
controlled statement. For example:
if (c)
int i; // [A] scope is within the if-stmt
else if (c2)
foo(); // [B] scope is within the if-stmt
else
{
int j; // [C] scope is also within the if-stmt
}
Another reason might be because declarations are allowed (see above),
which means (like you said) that constructor/destructor calls are
allowed within the scope of the controlling statement. Since C99
does not allow declarations as controlled statements (making [A]
illegal), this is a non-issue in C99.
Or perhaps they simply decided that it made more sense to treat
compound-statements and simple-statements the same, so that [C]
does not create an extra scope.
-- David R. Tribble, david@tribble.com, http://david.tribble.com --
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]