"Essay" #与 # #的使用含义与区别

Source: Internet
Author: User
Tags define definition

To put it simply,#连接字符串, # #连接两个参数

There are several steps involved in extending the # define definition symbols and macros in your program.

1. When calling a macro, first check the parameters to see if any symbols defined by # define are included. If they are, they are first replaced.

2. The replacement text is then inserted into the location of the original text in the program. For macro, the parameter names are replaced by their values.

3. Finally, scan the result file again to see if it contains any symbols defined by # define. If so, repeat the above process.


Macro and # define definitions can contain symbols for other # define definitions. However, a macro cannot have recursion.

# # The connection symbol is made up of two #, and its function is to join the two substrings (tokens) in the macro definition with parameters to form a new substring. But it cannot be the first or last substring. The so-called substring (token) refers to the smallest syntax unit that the compiler can recognize.

It can be spliced with symbols (token-pasting operator).

There is an example on MSDN:

#define PASTER (N) printf ("token" #n "=%d\n", token# #n)

int token9 = 100;

Call Paster (9) Again, and token# #n直接合并变成了token9 after the macro expands. The entire statement becomes a

printf ("token" "9" "=%d", token9);

In the C language, two concatenated double quotes in the string are automatically ignored, and the above sentence is equivalent to

printf ("Token9 =%d", token9);.

i.e. Output TOKEN9 = 100


"Essay" #与 # #的使用含义与区别

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.