The use of macros in C language, a few points to note

Source: Internet
Author: User

Defining some macros using # define, making some neat substitutions, and even some macros with parameters, are common in Linux C code, which means it's good and useful.

But it also has some complicated rules and traps to note, and I'll record some of them for reference only.

1, when using "\" To change lines, the second line to shelf write, otherwise there will be more than a space. For example:

#define OW "What is you doi \
Ng? "
The second row of ng? " There is no shelf to write, so when the substitution is made, it will:
What is you doi ng?
The correct definition is:
#define OW "What is you doi\
Ng? "

2. The macro can replace the length of the array, but const-defined constants are not allowed.

#define LIMIT 60
const int lmt=12;
int A[limit]; Effective

int A[LMT]; Invalid
Cause: In C, the size of the non-automatic array should be an integer constant expression, which means that the group size must be
A combination of integral constants (such as 5), enumeration constants, and sizeof expressions, but does not include the value of a const declaration.

The use of macros in C language, a few points to note

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.