Re: Error when compiling blocks code in Snow Leopard
Re: Error when compiling blocks code in Snow Leopard
- Subject: Re: Error when compiling blocks code in Snow Leopard
- From: Terry Lambert <email@hidden>
- Date: Thu, 3 Sep 2009 13:40:20 -0700
The C++ standard limits the scope of variables declared like you are
declaring 'i' (as a for-init-statement, technically) to the for
itself, rather than extending to the end of the enclosing scope. This
is a standards related change in behaviour from traditional C++/g++,
which, while not permitted by the standard, is how old compilers
tended to be implemented, not having an explicit indicator for
interior scope ends in their parse tree representation.
You will get the same behavior for the C compiler, were you to specify
the -ffor-scope option.
Obviously, block scopes are asynchronous, and have to persist to the
end of the enclosing scope, so the variables you use in them have to
do so as well.
-- Terry
On Sep 3, 2009, at 2:21 AM, Stéphane Letz wrote:
Hi,
We are experimenting with blocks in Snow Leopard and have the
following error when compiling C++ code:
class Foo {
void Bar()
{
dispatch_block_t b =
^{
for (int i = 0; i < 10; i++) {
}
};
}
};
test.cpp: In function ‘void __Bar_block_invoke_22(void*)’:
test.cpp:1206: error: ‘int Foo::i’ is not a static member of ‘struct
Foo’
test.cpp:1206: error: ‘i’ was not declared in this scope
test: *** [all] Error 1
The same blocks definition compiles as pure C :
void Bar()
{
dispatch_block_t b =
^{
for (int i = 0; i < 10; i++) {
}
};
}
Are they any limitation for use of local variables in blocks when
compiled in C++?
Thanks.
Stéphane Letz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden