#define Preprocessing directives (c++,c#,vb.net)

Source: Internet
Author: User

In C + +, we can define the so-called symbolic constants by #define This instruction, which is directly compiled into binary code. In this case, it is basically the same as the effect of the constant value variable defined with Const. Of

For example:

But #define also has the function of changing compiler behavior, for example, depending on whether or not you want to compile a code

The following code is available in many C + + source files

#if !defined(AFX_MAINFRM_H__0EFEA8A4_112C_4528_B7A8_761F1B02C20C__INCLUDED_) //如果没有定义
#define AFX_MAINFRM_H__0EFEA8A4_112C_4528_B7A8_761F1B02C20C__INCLUDED_ //那么就定义
#if _MSC_VER > 1000 //如果某个符号常量大于1000
#pragma once
#endif // _MSC_VER > 1000

So, this behavior is. NET inside is how to express it?

1. #define is inherited as a compilation instruction in C #.

#define DEBUG

"Note" In C #, you cannot assign a value to a defined symbol, for example, the following statement is invalid

#define Debug=true

That is, #define只需要定义即可, not (and not necessarily) specifying the value of this symbol

In subsequent code, it is also a syntax such as #if to determine whether a symbol is defined.

2.VB. NET also has a similar implementation, but it does not use the #define keyword, but instead uses the #const keyword

#Const MINI = 1
#Const VERSION = 1.0
Const MINI As String = "4"
#Region "这是一个代码块"
Sub Main()
#If MINI = 1 Then
Console.WriteLine("Hello.world")
#End If
End Sub
#End Region

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.