Macros in C Language (translation) 1

Source: Internet
Author: User

For the original article, see here

Macro, a small piece namedCode. InProgramWhen this name is referenced elsewhere, the compiler will automatically replace it with macro content. There are two types of macros. Their differences are mostly manifested in the Code:Object-likeMacros refer to objects, whileFunction-likeMacro refers to function call.

You can define any valid identifier as a macro, connectedC LanguageCan also be reserved, because the Preprocessor does not know which strings are reserved words. This feature is useful in some scenarios. For example, if you want to block the keyword const, because some old compilers do not support const, you can leave the const keyword define empty. However, there are some exceptions. For example, the keywords "defined" used by the pre-processor and the operators (+,-, *,/, =, and so on) in C ++ cannot be defined as macros.

The following content will cover the content

  1. Object-like macro
  2. Function-like macro
  3. Macro Parameters
  4. Character-based
  5. Join
  6. Variable Parameter macro
  7. Predefined macros
  8. Undefined macros and repeated definition macros
  9. Macro Parameter
  10. Macro trap

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.