Compare the similarities and differences between macro parameters and functions.

Source: Internet
Author: User

Compare the similarities and differences between parameters with macros and functions

From http://blog.csdn.net/piaojun_pj/article/details/5932639

 

 

The compiler processes Macros in the pre-compilation phase of the program. It mainly replaces Macros in the source file with pre-compilation commands.

 

1. Macros will be replaced simply when the compiler compiles the source code, without any logic detection, that is, simple code replication.

2. When macro is defined, the parameter type is not considered.

3. The use of the parameter Macro will make multiple copies of the same code block in the target file, which will increase the size of the target file.

4. The parameter macro runs faster than the function because the parameter pressure stack/out stack operation is not required.

5. Be careful when defining the parameter macro and add brackets.

6. Only one function exists in the target file, saving program space.

7. function calls involve parameter transfer and stack/output operations, which are relatively slow.

8. The function parameter has the problem of passing values and passing addresses (pointers), and the parameter macro does not exist.

 

Compare the similarities and differences between parameters with macros and functions

From http://blog.csdn.net/piaojun_pj/article/details/5932639

 

 

The compiler processes Macros in the pre-compilation phase of the program. It mainly replaces Macros in the source file with pre-compilation commands.

 

1. Macros will be replaced simply when the compiler compiles the source code, without any logic detection, that is, simple code replication.

2. When macro is defined, the parameter type is not considered.

3. The use of the parameter Macro will make multiple copies of the same code block in the target file, which will increase the size of the target file.

4. The parameter macro runs faster than the function because the parameter pressure stack/out stack operation is not required.

5. Be careful when defining the parameter macro and add brackets.

6. Only one function exists in the target file, saving program space.

7. function calls involve parameter transfer and stack/output operations, which are relatively slow.

8. The function parameter has the problem of passing values and passing addresses (pointers), and the parameter macro does not exist.

 

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.