Link character in C Language

Source: Internet
Author: User

As mentioned in the previous article # connector, this time I finally found an article that can explain the problem well:

 

From http://blog.csdn.net/killer_wy1985/archive/2010/04/07/5458576.aspx

 

Link character in C Language

(1) # connector and # Operator in macro definition
# The Concatenation symbol is composed of two pound signs. Its function is to connect 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 token refers to the minimum syntax unit that the compiler can recognize. The specific definition has a detailed explanation in the compilation principle, but it does not matter if you do not know. At the same time, it is worth noting that the # operator replaces the passed parameters as strings. Let's take a look at how they work. This is an example on msdn.
HypothesisProgramHas defined such a macro with parameters:
# Define Paster (n) printf ("token" # N "= % d", Token # N)
At the same time, an integer variable is defined:
Int token9 = 9;
Call this macro in the following way in the main program:
Paster (9 );
During compilation, the above sentence is extended:
Printf ("token" "9" "= % d", token9 );
Note that in this example, the "9" in Paster (9); is regarded as a string and connected with the "token", thus becoming the token9. # N is also replaced by "9.
As you can imagine, the result of running the program above is to print token9 = 9 on the screen.

(2) "/" and a macro with a long number of rows
The macro definition can contain more than two lines of commands. In this case, you must add "/" on the rightmost side and the line "/". No more characters are allowed, and no comments are allowed, the following line must end with "/", "/" followed by a space, and an error will be reported, not to mention it.
# Define Exchange (a, B ){/
Int t ;/
T = ;/
A = B ;/
B = T ;/
}

 

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.