C Language: Macro definitions with parameters

Source: Internet
Author: User

Naming conventions for macro names

1. All caps have multiple words separated by underscores (commonly used)

2. The hump mark starting with K (not commonly used)

Macro definition with parameters: Place the name of the macro after the macro name in the parentheses after the argument into the expression after the macro, and then replace

Format: #define Macro name (argument list) expression

Note: 1. No type in the parameter list

2, the macro name and parentheses must not add space between

The difference between a macro and a function with parameters

1, the function has a call process, will open up new storage space, need to spend some overhead

2, the macro is only to do a replacement operation

Usage scenarios:

1, when the calculation is relatively simple, the parameters are less when the use of macros, macros to improve the efficiency of operations

2, when the logic is more complex, more parameters when using the function

The macro's note point:

1, if you do the problem, the macro is just to do a replacement operation

2, if you write the macro definition, then all the parameters and the results of the operation of the place to add parentheses

3, the macro has some inherent shortcomings is no way to eliminate, in the use of macros with parameters do not use the parameter + +--= =/= *=%=

C Language: Macro definitions with parameters

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.