Blocks is an extension of the C language, with an anonymous function with automatic variables.
C function pointer type variable vs Block type variable
C function pointer type variable |
Block type variable |
return value type method name parameter list expression int func (int count) {return count + 1;} |
^ return value type parameter list expression ^int (int count) {return count+1;} |
Declares a function pointer type variable int (*funcptr) (int); |
Declares a block type variable int (^blk) (int); |
Assigns the defined function address to the function pointer type variable int (*funcptr) (int) = &func; |
Use the block syntax to assign a block to the block type variable int (^blk) (int) = ^int (int count) {return count+1;}; |
The complete block syntax differs from the general C-language function definition by only two points: (1) No function name (2) with "^"
using block type variables in function parameters and return values for comparison of descriptions
Do not want TypeDef to declare block type |
Use typedef to declare block type typedef int (^blk_t) (int); |
void func (int (^blk) (int)) {} |
void func (blk_t blk) {} |
Int (^func ()) (int) {return ^int (int count) {return count+1;};} |
blk_t func () {blk_t blk = ^int (int count) {return count+1;}; return BLK;} |
Bock Basic Knowledge