返回块驻留在本地堆栈上 [英] Returning block that lives on the local stack
本文介绍了返回块驻留在本地堆栈上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
clang分析器可以检查返回的基于堆栈的内存.
The clang analyzer can check for returning stack-based memory.
dispatch_block_t getPrintBlock (const char *msg) {
return ^{
printf("%s", msg);
};
}
引发此错误:returning block that lives on the local stack
此错误是什么意思?
推荐答案
您需要复制该块以将其移动到堆中.
You need to make a copy of the block to move it to the heap.
即像这样:
dispatch_block_t createPrintBlock (const char *msg) {
return Block_copy(^{
printf("%s", msg);
}) ;
}
这篇关于返回块驻留在本地堆栈上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文