The difference between block and C language function pointers __ function

Source: Internet
Author: User

Block is an anonymous function with an automatic variable value.


1. The function pointer is a reference to the address of a function that has been determined at compile time. Block is a function object, which is produced during the process of program running. The block object generated in one scope is allocated on the stack (stack) and, like all other objects allocated on the stack, is absent from the scope.
2, blocks is inline, and it is read-only to local variables. If you want to modify the keyword: __block (note that two underscores).

3, as a function of the parameters, blocks a sense of substitution of the callback function or delegate. When the function is called, suppose an event triggers, then the contents of the blocks will run. This facilitates the integration and reading of the code, and you don't need to implement the delegate method everywhere.

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.