You can copy a block and even pass it to other threads for deferred
execution (or,within its own thread,to a runloop). The compiler and
runtime arrange that all variables referenced from the block are
preserved for the life of all copies of the block. Although blocks are
available to pure C and C++,a block is also always an Objective-C
object.
我一直试图从最后一句话中弄清楚,但没有成功.句子的第一部分和第二部分似乎与我不相容(我可能遗漏了一些东西).这是否意味着块在C/C++和目标C中不是一回事?这是由于捕获了目标C中的块对象的方式吗?
解决方法
Objective-C extends the definition of a Block reference type to be
that also of id. A variable or expression of Block type may be
messaged or used as a parameter wherever an id may be. The converse is
also true. Block references may thus appear as properties and are
subject to the assign,retain,and copy attribute logic that is
reserved for objects.All Blocks are constructed to be Objective-C objects regardless of
whether the Objective-C runtime is operational in the program or not.
Blocks using automatic (stack) memory are objects and may be messaged,
although they may not be assigned into __weak locations if garbage
collection is enabled.
尽管我仍然对块运行时是否以相同的方式处理Objective C和C(即使编译纯C也创建Objective C对象)以及apple’s proposed extension to C是否允许在C/C++中使用块而不创建Objective C对象.欢迎评论.