#import <Foundation/Foundation.h>
int(^getCounter(void))(void)
{
__block int counter;
int(^block)(void)=^(void){ return counter++; };
return _Block_copy(block);
}
int main (void)
{
int (^block)(void) = getCounter();
block();
block();
NSCAssert(block() == 2, @"Block counted incorrectly");
int(^block2)(void) = getCounter();
block2();
block2();
NSCAssert(block2() == 2, @"Block didn't start from 0");
NSLog(@"%d", block2());
return 0;
}
int(^getCounter(void))(void)
{
__block int counter;
int(^block)(void)=^(void){ return counter++; };
return _Block_copy(block);
}
int main (void)
{
int (^block)(void) = getCounter();
block();
block();
NSCAssert(block() == 2, @"Block counted incorrectly");
int(^block2)(void) = getCounter();
block2();
block2();
NSCAssert(block2() == 2, @"Block didn't start from 0");
NSLog(@"%d", block2());
return 0;
}
#import <Foundation/Foundation.h>
int(^getCounter(void))(void)
{
__block int counter;
int(^block)(void)=^(void){ return counter++; };
return _Block_copy(block);
}
int main (void)
{
int (^block)(void) = getCounter();
block();
block();
NSCAssert(block() == 2, @"Block counted incorrectly");
int(^block2)(void) = getCounter();
block2();
block2();
NSCAssert(block2() == 2, @"Block didn't start from 0");
NSLog(@"%d", block2());
return 0;
}
int(^getCounter(void))(void)
{
__block int counter;
int(^block)(void)=^(void){ return counter++; };
return _Block_copy(block);
}
int main (void)
{
int (^block)(void) = getCounter();
block();
block();
NSCAssert(block() == 2, @"Block counted incorrectly");
int(^block2)(void) = getCounter();
block2();
block2();
NSCAssert(block2() == 2, @"Block didn't start from 0");
NSLog(@"%d", block2());
return 0;
}