Re: C arrays as __block variables
Re: C arrays as __block variables
- Subject: Re: C arrays as __block variables
- From: Tony Romano <email@hidden>
- Date: Sat, 26 Jun 2010 23:09:49 -0700
- (void)_copyOrMoveURLs:(SEL) s opMove:(BOOL)op src:(NSDictionary *)URLs
completionHandler:(void (^)(NSDictionary *newURLs, NSError *error))handler
{
__block char array1[5];
array1[0] = 'W';
NSBlockOperation * foo = [NSBlockOperation blockOperationWithBlock:^{
array1[1] = array1[0];
char b = array1[0];
NSLog(@"char %c %c %c", array1[0], array1[1], b);
}];
}
Works fine using 3.2.2 prints out char W W W
-Tony
On Jun 26, 2010, at 9:19 PM, Bill Bumgarner wrote:
>
> On Jun 26, 2010, at 9:14 PM, Tony Romano wrote:
>
>> That's why I asked for an example of what the op question is
>
> http://lists.apple.com/archives/cocoa-dev/2010/Jun/msg01040.html
>
>> This would seem to imply that a __block variable *can* be a *fixed* length
>> array. But when I try to write into such an array inside a block, I get a
>> compile error, "cannot access __block variable of array type inside block."
>
> void foo() {
> __block char barfy[100];
>
> ^() {
> char b = barfy[0]; <<<< error: cannot access __block variable of array type inside block
> b = b;
> };
> }
>
> void bar() {
> __block struct angus {
> char barfy[100];
> } kangus;
>
> ^() {
> char b = kangus.barfy[0]; // compiles fine
> b = b;
> };
> }
>
> The reason being that a Block_copy() or [block copy] will cause the __block variables to be moved to the heap and, thus, the compiler must know the exact size of all variables to be copied when emitting the copy helper.
>
> b.bum
>
-Tony
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden