The Application of C ++ programming language is flexible. Its appearance has brought a lot of help to programmers. So what are the features of other programming languages? Let's start with the features of the C ++ # define pre-processing command and compare it with other languages.
C ++ # define pre-processing commands define so-called symbolic constants, which are directly compiled into binary code. In this case, it is similar to the effect of a constant variable defined by const. ,
But # define also has a function, that is, to change the compiler behavior, for example, decide whether to compile a certain sentence of code based on it.
The following code about the C ++ # define preprocessing command is available in many C ++ source files:
- # If! Defined (afx_mainfrm_h%0efea8a4_%c_4528 _
B7a8_761f1b02c20c00000000ded _) // If Not Defined
- # Define afx_mainfrm_h1_0efea8a4_1_c_4528_b7a8 _
761f1b02c20c00000000ded _ // is defined
- # If _ MSC_VER> 1000 // if a symbolic constant is greater than 1000
- # Pragma once
- # Endif // _ MSC_VER> 1000
So how does this behavior behave in. NET?
- Implementation Code of C ++ one-way linked list
- Basic concepts of C ++ void
- Summary of C ++ void rules
- Specific implementation scheme of C ++ simulating event keywords
- C ++ two-dimensional array initialization related application skills
1. C # inherits the role of # define as the Compilation instruction.
# Define DEBUG
Note: in C #, you cannot assign values to the defined symbols. For example, the following statement is invalid.
# Define DEBUG = TRUE
That is to say, # define only needs to be defined, and does not need to) specify the value of this symbol
In subsequent code, the # if syntax is used to determine whether a symbol is defined.
2. VB. NET has similar implementations, but it does not use the # define keyword, but the # const keyword.
- # Const MINI = 1
- # Const VERSION = 1.0
- Const MINI As String = "4"
- # Region "this is a code block"
- Sub Main ()
- # If MINI = 1 Then
- Console. WriteLine ("Hello. world ")
- # End If
- End Sub
- # End Region
The preceding section describes the differences between the pre-processing commands of C ++ # define and other languages.