site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com -- Terry Hi, class Foo { void Bar() { dispatch_block_t b = ^{ for (int i = 0; i < 10; i++) { } }; } }; The same blocks definition compiles as pure C : void Bar() { dispatch_block_t b = ^{ for (int i = 0; i < 10; i++) { } }; } Thanks. Stéphane Letz _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/tlambert%40apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... 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. On Sep 3, 2009, at 2:21 AM, Stéphane Letz wrote: We are experimenting with blocks in Snow Leopard and have the following error when compiling C++ code: 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 Are they any limitation for use of local variables in blocks when compiled in C++? This email sent to tlambert@apple.com This email sent to site_archiver@lists.apple.com