1{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf430 2{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Monaco;} 3{\colortbl;\red255\green255\blue255;\red0\green0\blue0;} 4\margl1440\margr1440\margb1800\margt1800\vieww14920\viewh16280\viewkind0 5\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 6 7\f0\fs52 \cf0 Language Specification for Blocks\ 8\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 9 10\fs24 \cf0 \ 112008/2/25 \'97 created\ 122008/7/28 \'97 revised, 13\f1\fs20 __block 14\f0\fs24 syntax\ 152008/8/13 \'97 revised, Block globals\ 162008/8/21 \'97 revised, C++ elaboration\ 172008/11/1 \'97 revised, 18\f1\fs20 __weak 19\f0\fs24 support\ 202009/1/12 \'97 revised, explicit return types\ 212009/2/10 \'97 revised, __block objects need retain\ 22\ 23\pard\pardeftab720\ql\qnatural 24\cf0 Copyright 2008-2009 Apple, Inc.\'a0Permission is hereby granted, free of charge, to any person obtaining a copy\'a0of this software and associated documentation files (the "Software"), to deal\'a0in the Software without restriction, including without limitation the rights\'a0to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\'a0copies of the Software, and to permit persons to whom the Software is\'a0furnished to do so, subject to the following conditions:\ 25\ 26The above copyright notice and this permission notice shall be included in\'a0all copies or substantial portions of the Software.\ 27\ 28THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\'a0\'a0IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\'a0\'a0FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\'a0\'a0AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\'a0\'a0LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\'a0OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\'a0THE SOFTWARE.\ 29\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 30\cf0 \ 31\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 32 33\b\fs28 \cf0 The Block Type\ 34\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 35 36\b0\fs24 \cf0 \ 37A new 38\i derived type 39\i0 is introduced to C and, by extension, Objective-C, C++, and Objective-C++. Like function types, the Block type is a pair consisting of a result value type and a list of parameter types very similar to a function type. Blocks are intended to be used much like functions with the key distinction being that in addition to executable code they also contain various variable bindings to automatic (stack) or managed (heap) memory.\ 40\ 41The abstract declarator 42\f1\fs20 int (^)(char, float) 43\f0\fs24 describes a reference to a Block that, when invoked, takes two parameters, the first of type 44\f1\fs20 char 45\f0\fs24 and the second of type 46\f1\fs20 float 47\f0\fs24 , and returns a value of type 48\f1\fs20 int 49\f0\fs24 . The Block referenced is of opaque data that may reside in automatic (stack) memory, global memory, or heap memory.\ 50\ 51\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 52 53\b\fs28 \cf0 \ 54Block Variable Declarations\ 55\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 56 57\b0\fs24 \cf0 \ 58A variable with Block type is declared using function pointer style notation substituting 59\f1\fs20 ^ 60\f0\fs24 for 61\f1\fs20 * 62\f0\fs24 . The following are valid Block variable declarations:\ 63\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 64 65\f1\fs20 \cf0 void (^blockReturningVoidWithVoidArgument)(void);\ 66 int (^blockReturningIntWithIntAndCharArguments)(int, char);\ 67 void (^arrayOfTenBlocksReturningVoidWithIntArgument[10])(int);\ 68\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 69 70\f0\fs24 \cf0 \ 71Variadic 72\f1\fs20 ... 73\f0\fs24 arguments are supported. [variadic.c] A Block that takes no arguments must specify void in the argument list [voidarg.c]. An empty parameter list does not represent, as K&R provide, an unspecified argument list. Note: both gcc and clang support K&R style as a convenience.\ 74\ 75A Block reference may be cast to a pointer of arbitrary type and vice versa. [cast.c] A Block reference may not be dereferenced via the pointer dereference operator 76\f1\fs20 * 77\f0\fs24 , and thus a Block's size may not be computed at compile time. [sizeof.c]\ 78\ 79\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 80 81\b\fs28 \cf0 \ 82Block Literal Expressions\ 83\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 84 85\b0\fs24 \cf0 \ 86A Block literal expression produces a reference to a Block. It is introduced by the use of the 87\f1\fs20 ^ 88\f0\fs24 token as a unary operator. \ 89\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 90 91\f1\fs20 \cf0 Block_literal_expression ::= ^ block_decl compound_statement_body\ 92 block_decl ::= \ 93 block_decl ::= parameter_list\ 94 block_decl ::= type_expression\ 95\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 96 97\f0\fs24 \cf0 \ 98...where type expression is extended to allow 99\f1\fs20 ^ 100\f0\fs24 as a Block reference (pointer) where 101\f1\fs20 * 102\f0\fs24 is allowed as a function reference (pointer).\ 103\ 104The following Block literal:\ 105\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 106 107\f1\fs20 \cf0 ^ void (void) \{ printf("hello world\\n"); \}\ 108\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 109 110\f0\fs24 \cf0 \ 111...produces a reference to a Block with no arguments with no return value.\ 112\ 113The return type is optional and is inferred from the return statements. If the return statements return a value, they all must return a value of the same type. If there is no value returned the inferred type of the Block is 114\f1\fs20 void 115\f0\fs24 ; otherwise it is the type of the return statement value.\ 116\ 117If the return type is omitted and the argument list is 118\f1\fs20 ( void ) 119\f0\fs24 , the 120\f1\fs20 ( void ) 121\f0\fs24 argument list may also be omitted.\ 122\ 123So:\ 124\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 125 126\f1\fs20 \cf0 ^ ( void ) \{ printf("hello world\\n"); \}\ 127\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 128 129\f0\fs24 \cf0 \ 130...and:\ 131\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 132 133\f1\fs20 \cf0 ^ \{ printf("hello world\\n"); \}\ 134\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 135 136\f0\fs24 \cf0 \ 137...are exactly equivalent constructs for the same expression.\ 138\ 139The 140\f1\fs20 type_expression 141\f0\fs24 extends C expression parsing to accommodate Block reference declarations as it accommodates function pointer declarations.\ 142\ 143Given:\ 144\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 145 146\f1\fs20 \cf0 typedef int (*pointerToFunctionThatReturnsIntWithCharArg)(char);\ 147 pointerToFunctionThatReturnsIntWithCharArg functionPointer;\ 148\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 149 150\f0\fs24 \cf0 \ 151\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 152 153\f1\fs20 \cf0 ^ pointerToFunctionThatReturnsIntWithCharArg (float x) \{ return functionPointer; \}\ 154\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 155 156\f0\fs24 \cf0 \ 157...and: 158\f1\fs20 \ 159 ^ int ((*)(float x))(char) \{ return functionPointer; \}\ 160 161\f0\fs24 \ 162...are equivalent expressions, as is:\ 163\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 164 165\f1\fs20 \cf0 \ 166 ^(float x) \{ return functionPointer; \}\ 167\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 168 169\f0\fs24 \cf0 \ 170[returnfunctionptr.c]\ 171\ 172The compound statement body establishes a new lexical scope within that of its parent. Variables used within the scope of the compound statement are bound to the Block in the normal manner with the exception of those in automatic (stack) storage. Thus one may access functions and global variables as one would expect, as well as static local variables. [testme]\ 173\ 174Local 175\i automatic 176\i0 (stack) variables referenced within the compound statement of a Block are imported and captured by the Block as const copies. The capture (binding) is performed at the time of the Block literal expression evaluation.\ 177\ 178The lifetime of variables declared in a Block is that of a function; each activation frame contains a new copy of variables declared within the local scope of the Block. Such variable declarations should be allowed anywhere [testme] rather than only when C99 parsing is requested, including 179\f1\fs20 \cf2 for 180\f0\fs24 \cf0 statements. [testme]\ 181\ 182Block literal expressions may occur within Block literal expressions (nest) and all variables captured by any nested blocks are implicitly also captured in the scopes of their enclosing Blocks.\ 183\ 184A Block literal expression may be used as the initialization value for Block variables at global or local static scope.\ 185\ 186\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 187 188\b\fs28 \cf0 \ 189The Invoke Operator\ 190\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 191 192\b0\fs24 \cf0 \ 193Blocks are invoked using function call syntax with a list of expression parameters of types corresponding to the declaration and returning a result type also according to the declaration. Given:\ 194\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 195 196\f1\fs20 \cf0 int (^x)(char);\ 197 void (^z)(void);\ 198 int (^(*y))(char) = &x;\ 199\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 200 201\f0\fs24 \cf0 \ 202...the following are all legal Block invocations:\ 203\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 204 205\f1\fs20 \cf0 x('a');\ 206 (*y)('a');\ 207 (true ? x : *y)('a')\ 208\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 209 210\f0\fs24 \cf0 \ 211\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 212 213\b\fs28 \cf0 \ 214The Copy and Release Operations\ 215\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 216 217\b0\fs24 \cf0 \ 218The compiler and runtime provide copy and release operations for Block references that create and, in matched use, release allocated storage for referenced Blocks.\ 219\ 220The copy operation 221\f1\fs20 Block_copy() 222\f0\fs24 is styled as a function that takes an arbitrary Block reference and returns a Block reference of the same type. The release operation, 223\f1\fs20 Block_release() 224\f0\fs24 , is styled as a function that takes an arbitrary Block reference and, if dynamically matched to a Block copy operation, allows recovery of the referenced allocated memory.\ 225\ 226\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 227 228\fs28 \cf0 \ 229\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 230 231\b \cf0 The 232\f1\b0 __block 233\f0\b Storage Qualifier\ 234\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 235 236\b0\fs24 \cf0 \ 237In addition to the new Block type we also introduce a new storage qualifier, 238\f1\fs20 __block 239\f0\fs24 , for local variables. [testme: a __block declaration within a block literal] The 240\f1\fs20 __block 241\f0\fs24 storage qualifier is mutually exclusive to the existing local storage qualifiers 242\f1\fs20 auto 243\f0\fs24 , 244\f1\fs20 register 245\f0\fs24 , and 246\f1\fs20 static 247\f0\fs24 .[testme] Variables qualified by __block act as if they were in allocated storage and this storage is automatically recovered after last use of said variable. An implementation may choose an optimization where the storage is initially automatic and only "moved" to allocated (heap) storage upon a Block_copy of a referencing Block. Such variables may be mutated as normal variables are.\ 248\ 249In the case where a __block variable is a Block one must assume that the __block variable resides in allocated storage and as such is assumed to reference a Block that is also in allocated storage (that it is the result of a Block_copy operation). Despite this there is no provision to do a Block_copy or a Block_release if an implementation provides initial automatic storage for Blocks. This is due to the inherent race condition of potentially several threads trying to update the shared variable and the need for synchronization around disposing of older values and copying new ones. Such synchronization is beyond the scope of this language specification.\ 250\ 251\ 252\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 253 254\b\fs28 \cf0 Control Flow\ 255\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 256 257\b0 \cf0 \ 258\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 259 260\fs24 \cf0 The compound statement of a Block is treated much like a function body with respect to control flow in that 261\f1\fs20 goto 262\f0\fs24 , 263\f1\fs20 break 264\f0\fs24 , and 265\f1\fs20 continue 266\f0\fs24 do not escape the Block. Exceptions are treated "normally" in that when thrown they pop stack frames until a catch clause is found.\ 267\ 268\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 269 270\b\fs28 \cf0 \ 271\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 272 273\fs32 \cf0 Objective-C Extensions 274\b0\fs36 \ 275\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 276 277\fs24 \cf0 \ 278Objective-C extends the definition of a Block reference type to be that also of 279\f1\fs20 id 280\f0\fs24 . A variable or expression of Block type may be messaged or used as a parameter wherever an 281\f1\fs20 id 282\f0\fs24 may be. The converse is also true. Block references may thus appear as properties and are subject to the 283\f1\fs20 assign 284\f0\fs24 , 285\f1\fs20 retain 286\f0\fs24 , and 287\f1\fs20 copy 288\f0\fs24 attribute logic that is reserved for objects.\ 289\ 290All 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 291\f1\fs20 __weak 292\f0\fs24 locations if garbage collection is enabled.\ 293\ 294Within a Block literal expression within a method definition references to instance variables are also imported into the lexical scope of the compound statement. These variables are implicitly qualified as references from 295\f1\fs20 self 296\f0\fs24 , and so 297\f1\fs20 self 298\f0\fs24 is imported as a const copy. The net effect is that instance variables can be mutated.\ 299\ 300The 301\f1\fs20 Block_copy 302\f0\fs24 operator retains all objects held in variables of automatic storage referenced within the Block expression (or form strong references if running under garbage collection). Object variables of 303\f1\fs20 __block 304\f0\fs24 storage type are assumed to hold normal pointers with no provision for retain and release messages.\ 305\ 306Foundation defines (and supplies) 307\f1\fs20 -copy 308\f0\fs24 and 309\f1\fs20 -release 310\f0\fs24 methods for Blocks.\ 311\ 312In the Objective-C and Objective-C++ languages, we allow the 313\f1\fs20 __weak 314\f0\fs24 specifier for 315\f1\fs20 __block 316\f0\fs24 variables of 317\f1\fs20 object 318\f0\fs24 type. If garbage collection is not enabled, this qualifier causes these variables to be kept without retain messages being sent. This knowingly leads to dangling pointers if the Block (or a copy) outlives the lifetime of this object.\ 319\ 320In garbage collected environments, the 321\f1\fs20 __weak 322\f0\fs24 variable is set to 323\f1\fs20 nil 324\f0\fs24 when the object it references is collected, as long as the 325\f1\fs20 __block 326\f0\fs24 variable resides in the heap (either by default or via 327\f1\fs20 Block_copy() 328\f0\fs24 ). The initial Apple implementation does in fact start 329\f1\fs20 __block 330\f0\fs24 variables on the stack and migrate them to the heap only as a result of a 331\f1\fs20 Block_copy() 332\f0\fs24 operation.\ 333\ 334It is a runtime error to attempt to assign a reference to a stack-based Block into any storage marked 335\f1\fs20 __weak 336\f0\fs24 , including 337\f1\fs20 __weak __block 338\f0\fs24 variables.\ 339\ 340\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 341 342\b\fs28 \cf0 \ 343\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 344 345\fs32 \cf0 C++ Extensions\ 346\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 347 348\b0\fs24 \cf0 \ 349Block literal expressions within functions are extended to allow const use of C++ objects, pointers, or references held in automatic storage.\ 350\ 351For example, given class 352\f1\fs20 Foo 353\f0\fs24 with member function 354\f1\fs20 fighter(void) 355\f0\fs24 :\ 356\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 357 358\f1\fs20 \cf0 Foo foo;\ 359 Foo &fooRef = foo;\ 360 Foo *fooPtr = &foo;\ 361\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 362 363\f0\fs24 \cf0 \ 364...a Block that used 365\f1\fs20 foo 366\f0\fs24 would import the variables as const variations:\ 367\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 368 369\f1\fs20 \cf0 const Foo block_foo = foo; // const copy constructor\ 370 const Foo &block_fooRef = fooRef;\ 371 const Foo *block_fooPtr = fooPtr;\ 372\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 373 374\f0\fs24 \cf0 \ 375Stack-local objects are copied into a Block via a copy const constructor. If no such constructor exists, it is considered an error to reference such objects from within the Block compound statements. A destructor is run as control leaves the compound statement that contains the Block literal expression.\ 376\ 377If a Block originates on the stack, a const copy constructor of the stack-based Block const copy is performed when a 378\f1\fs20 Block_copy 379\f0\fs24 operation is called; when the last 380\f1\fs20 Block_release 381\f0\fs24 (or subsequently GC) occurs, a destructor is run on the heap copy.\ 382\ 383Variables declared as residing in 384\f1\fs20 __block 385\f0\fs24 storage may be initially allocated in the heap or may first appear on the stack and be copied to the heap as a result of a 386\f1\fs20 Block_copy() 387\f0\fs24 operation. When copied from the stack, a normal copy constructor is used to initialize the heap-based version from the original stack version. The destructor for a const copied object is run at the normal end of scope. The destructor for any initial stack based version is also called at normal end of scope.\ 388\ 389Within a member function, access to member functions and variables is done via an implicit const copy of a 390\f1\fs20 this 391\f0\fs24 pointer.\ 392\ 393Member variables that are Blocks may not be overloaded by the types of their arguments.\ 394}