C # preprocessing

Source: Internet
Author: User

C # defines multiple preprocessing commands, which can change the way the compiling system interprets the source program files. Before translating a program into the target code, the pre-processing command first takes effect on the text in the source file, that is, the compiled text. C # All preprocessing commands start with #, and each preprocessing command occupies a single line. The following table lists the pre-processing commands in C #2.0.

C # preprocessing commands




 

7.2.1 # define command
 
 
1. # The define command is used to define a string called a symbol. The # if and # elif commands can determine whether a compliance already exists and control the compilation process accordingly. # The basic form of the define command is as follows:
2.
3. # define symbol
4.
5. Note that it does not end with a semicolon because it is not a C # statement but a preprocessing command. # Use at least one space to separate define and symbol. C # This command is different from the # define command in C and C ++ (C and C ++ are used to define macros ).
6.
7. For example:
8.
9. # define Windows
 
7.2.2 # if, # elif, # else, And # endif commands
 
# The basic form of the if command is as follows:
 
1. # if symbol_expression_1
2.
3. statement_sequence_1
4.
5. # elif symbol_expression_2
6.
7. statement_sequence_2
8.
9. # else
10.
11. statement_sequence_n
12.
13. # endif
 
7.2.2 # if, # elif, # else, And # endif commands
 
Here, symbol_expression_ I is a logical expression composed of one or more symbrs. If the expression value is true, compile statement_sequence_ I. If all symbol_expressions are false, compile statement_sequence_n.
Example: P7_5
 
7.2.3 # undef command
 
1. # The undef command can cancel the previously defined symbols. The basic format is as follows:
2.
3. # undef symbol
4.
5. For example:
6.
7. # define SMALL
8.
9. // before this position, SMALL is defined.
10.
11.
12. # if SMALL
13.
14. # undef SMALL
15.
16.
 
7.2.4 # error command
 
 
 
1. # The error command is mainly used for debugging. It can force the compiler to stop compilation. The basic form of this command is as follows:
2.
3. # error error_message
4.
5. error_message indicates the error message. For example:
6.
7. # error An error occurred here!
 
7.2.5 # warning command www.2cto.com
 
 
1. # warning is similar to # error, but it generates a warning message instead of an error message. Therefore, the compilation process will not stop. The basic form is as follows:
2.
3. # warning warning_message
 
7.2.6 # line command
 
 
1. # The line command can set the line number and file name for the file where it is located. If an error or warning occurs during compilation, the line number and file name here will be used. # The basic form of line commands is:
2.
3. # line number "filename"
4.
5. number is any positive integer, which is used as the row number of the new line. Optional filename indicates any valid File Identifier, which is used as a new file name. # Line is mainly used for debugging and special applications.
6.
7. # The line command has two other drafts. One is default, which returns the row number based on the original position. Its usage is:
8.
9. # line default
10.
11. The other is hidden. When you debug a program step by step, the hidden option allows the compiler to skip the line between this command and the next # line command that does not contain the hidden option. The usage is as follows:
12.
13. # line hidden
 
7.2.7 # region and # endregion commands
 
 
1. # region and # endregion are used to define an area that can be expanded or shrunk in the Outline View of Visual Studio IDE. The basic form is as follows:
2.
3. # region region_name
4.
5. // code
6.
7.
8. # endregion
9.
10. region_name is used to specify the region name.
 
7.2.8 # program command
 
# The program command is newly added to C #2.0. It is used to give instructions, for example, specifying options for the compiler. The basic form is as follows:
# Program option
Here, option is the instruction passed to the compiler.
In C #2.0, # program supports two options. One is warning, which is used to enable or disable a specific compiler warning. The name is as follows:
 
1. # program warning disable warnings // disable warning
2.
3.
4. # program warning restore warnings
 
7.2.8 # program command
 
1. warnings is a list of comma-separated warning numbers. For example:
2.
3. # program warning disable 168 // disable the 168 warning
4.
5.
6. Another option is checksum. It is used to generate a checksum for ASP. NET projects. The basic form is as follows:
7.
8. # program checksum "filename" "{GUID}" "check-sum"
9.
10. filename is the file name, GUID is the Globally Unique Identifier related to the file name, and check-sum is a hexadecimal number that contains the checksum. The string must contain an even number.

 


From Tom

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.