#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;
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明原文出处。如若内容造成侵权/违法违规/事实不符,请联系SD编程学习网:675289112@qq.com进行投诉反馈,一经查实,立即删除!