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 19:48:15 -0700
hmmm. Your saying this doesn't work?
NSBlockOperation * foo = [NSBlockOperation blockOperationWithBlock:^{
__block char array1[5];
array1[0] = 'T';
}];
It works fine for me. Are you saying something different?
-Tony
On Jun 26, 2010, at 7:16 PM, Bill Bumgarner wrote:
>
> On Jun 26, 2010, at 6:38 PM, Matt Neuburg wrote:
>
>> The docs say: "There are two further restrictions on __block variables: they
>> cannot be variable length arrays, and cannot be structures that contain C99
>> variable-length arrays."
>>
>> 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."
>>
>> Who's mistaken, the compiler or the docs? Thx - m.
>
> Neither. The issue is that a block array in C is, technically, sorta-kinda variable length unless you do something to make it fixed length. I don't remember the exact details beyond that it is a subtle edge case.
>
> That something is typically to encapsulate it into a Struct.
>
> This:
>
> void foo() {
> char barfy[100];
>
> ^() {
> char b = barfy[0]; <<<< error: cannot access copied-in variable of array type inside block
> b = b;
> };
> }
>
> This compiles just fine:
>
> void bar() {
> struct angus {
> char barfy[100];
> } kangus;
>
> ^() {
> char b = kangus.barfy[0];
> b = b;
> };
> }
>
> b.bum
>
>
>
>
>
>
> _______________________________________________
>
> 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
>
-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