Recursive blocks
Recursive blocks
- Subject: Recursive blocks
- From: Glen Low <email@hidden>
- Date: Thu, 27 Jan 2011 10:45:23 +0800
I would like to call a block recursively. Since blocks are anonymous,
this would involve either naming the block or some way of accessing
the block reference from within the block.
Here's a first stab:
int main (int argc, const char * argv[]) {
int (^factorial2)(int) = ^(int n)
{
if (n == 1)
return 1;
else
return n * factorial2(n-1);
};
int i = factorial2(10);
return 0;
}
This seems to work well, except that when I run it through the static
analyzer in Xcode 3.2.5, it complains that the factorial2 variable is
captured by the block with a garbage value. If I make the block
variable though, it doesn't complain. Since the block works well
enough as-is, should I ignore this? If this is not per-spec, how would
I get the reference to the block from within the block in order to
call it recursively?
Cheers
Glen Low
Pixelglow Software
_______________________________________________
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