Differences between macros and functions in C Language

Source: Internet
Author: User

Differences between macros and functions in C Language
I. Code Length: the macro is completely replaced and inserted into the program to make the code longer. The function code only appears in one place and is called there when used. Ii. execution speed: the macro is faster, because it has been completed in the pre-compilation phase; the function is a little slower, because the additional time needed to call and return (pressure stack/out stack. 3. Operator priority: When a macro is present, parentheses are left blank, leading to a computing logic error. The function only returns the value at last, making the result easy to predict. Iv. parameter evaluation: the macro needs to be calculated every time. The function only needs to be calculated once. Subsequent calls do not cause multiple value calculation errors. 5. Parameter type: a macro does not care about the type, as long as the parameter operation is valid. The function types must be consistent, and different functions are required for different types.

Related Article

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.