The differences between C language (c + +) macros, inline functions, functions, and usage scenarios summary

Source: Internet
Author: User

(1) Parameter passing: macros can be easily inherited before the code variables, functions, inline functions are dependent on the parameters and global variables

(2) code generation macros and inline function generation are replaced when there is no stack at the time of the function call, so the execution efficiency will be higher than the function, without the risk of stack overflow, but will generate more code to occupy more space.

(3) Function and inline function to change the input parameters must be referenced or pointer

Macros

#define STR (str) #str means to add str ""

#define STR (str) x# #str means to connect str to X

An already special symbol cannot be used as a macro parameter.

The differences between C language (c + +) macros, inline functions, functions, and usage scenarios summary

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.