C ++ # define pre-processing command features Evaluation

Source: Internet
Author: User

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:

 
 
  1. # If! Defined (afx_mainfrm_h%0efea8a4_%c_4528 _
    B7a8_761f1b02c20c00000000ded _) // If Not Defined
  2. # Define afx_mainfrm_h1_0efea8a4_1_c_4528_b7a8 _
    761f1b02c20c00000000ded _ // is defined
  3. # If _ MSC_VER> 1000 // if a symbolic constant is greater than 1000
  4. # Pragma once
  5. # 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.

 
 
  1. # Const MINI = 1
  2. # Const VERSION = 1.0
  3. Const MINI As String = "4"
  4. # Region "this is a code block"
  5. Sub Main ()
  6. # If MINI = 1 Then
  7. Console. WriteLine ("Hello. world ")
  8. # End If
  9. End Sub
  10. # End Region

The preceding section describes the differences between the pre-processing commands of C ++ # define and other languages.

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.