unless I did something wrong, when I ran prog 13.9 modified with the __block modifier, my output is
foo = 15
foo = 20
which would make sense (the book currently says
foo = 10
foo = 20
)
Also, for readability, I'd suggest changing the comment as I did below, on the line
foo = 20;
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
__block int foo = 10;
void (^printFoo)(void) = ^(void) {
NSLog(@"foo = %i",foo);
foo = 20; // ** THIS LINE GENERATES A COMPILER ERROR WITHOUT THE __block MODIFIER
};
foo = 15;
printFoo();
NSLog(@"foo = %i",foo);
[pool drain];
return 0;
}