Re: crosses initialization
Re: crosses initialization
- Subject: Re: crosses initialization
- From: Kay Roepke <email@hidden>
- Date: Mon, 22 May 2006 20:24:42 +0200
On 21. May 2006, at 14:54 Uhr, Jonathan Taylor wrote:
Notice that the compiler is NOT objecting to the initialization of
temp2 or temp4, CW compiles the code fine, and GCC 4 certainly
always used to compile it ok until today(!). My understanding is
that (at least under C99) this is perfectly valid code as long as
the variables being initialized are basic types rather than classes
requiring constructors.
Hi!
Chiming in late, but this might be helpful anyway:
The C++ standard explicitely states that this program is ill-formed
(Section 6.7 Paragraph 3)
"It is possible to transfer into a block, but not in a way that
bypasses declarations with initialization. A program that jumps from
a point
where a local variable with automatic storage duration is not in
scope to a point where it is in scope is ill-formed unless the
variable has
POD type (3.9) and is declared without an initializer (8.5)"
The sample code given is:
void f() {
goto lx; // ill-formed
ly:
X a = 1;
lx:
goto ly; // ok
}
Thus temp and temp3 violate the initializer condition. Why temp2
doesn't isn't 100% clear to me, but I suspect that it has to do with
the fact that
static initializations of POD types is done before the scope is
entered as opposed to temp2 in your example (since it is not static
and thus not known
at scope entrance).
AFAIK gcc shouldn't have compiled this ever as valid ANSI C++. But
then again...;)
HTH,
Kay
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden