Bock Basic Knowledge

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.