Pre-compiled commands and related macro Summary

Source: Internet
Author: User
// ================================================ ========================================

// Title:

// Pre-compiled commands and related macro Summary

// Author:

// Norains

// Date:

// Saturday 10-December-2007

// Environment:

// Evc4.0 + Windows CE 5.0 standard SDK

// ================================================ ========================================

1. Pre-compiled commands

01 )#

Empty command, no effect

02) # include

ContainsSource codeFile

03) # define

Definition macro

04) # UNDEF

Cancel a defined macro

05) # If

If the given condition is true, compile the followingCode

06) # else

Compile as remaining options for other preprocessing

07) # ifdef

If the macro has been defined, compile the following code:

08) # ifndef

If the macro is not defined, compile the following code:

09) # Elif

If the previous # If condition is not true and the current condition is true, compile the following code:

10) # endif

End one # If ...... # Else Conditional compilation Block

11) # Line

Change the number of current lines and file name

12) # pragma

For CompilationProgramProvides unconventional control flow information

13) # error

Stop compilation and Display error messages

2. compiler-related macros

Only some related macros are listed in this article. To view the complete macro list, refer to the "predefined macros" section of msdn.

01) _ msc_ver

Microsoft compiler version macro.

The following table lists the values of compilers of each version:

Compiler _ msc_ver Value

-------------------------------------------

C compiler version 6.0 600

C/C ++ compiler version 7.0 700

Visual c ++, windows, version 1.0 800

Visual c ++, 32-bit, version 1.0 800

Visual c ++, windows, version 2.0 900

Visual c ++, 32-bit, version 2.x 900

Visual c ++, 32-bit, version 4.0 1000

Visual c ++, 32-bit, version 5.0 1100

Visual c ++, 32-bit, version 6.0 1200

Visual c ++, 32-bit, version 2002 1300

Visual c ++, 32-bit, Version 2003 1310

Visual c ++, 32-bit, Version 2005 1400

Embedded Visual C ++, 32-bit, version 4.0 cross 1200-1202

02) _ mfc_ver

MFC version macro.

Version _ mfc_ver Value

-------------------------------

4.21 0x0421

6.0 0x0600

7.0 0x0700

03) _ time __

The time when the current source file is compiled, in the format of "HH: mm: SS.

04) _ date __

Compile the date of the current source file, in the format of "Mmm dd YYYY.

05) _ file __

The name of the current source file to be compiled.

3. instance description

01) determine the current compiling environment based on the value of _ mfc_ver.

# If _ msc_ver> = 1400

// This is Visual C ++ 2005

# Elif _ msc_ver> = 1310

// This is Visual C ++. NET 2003

# Elif _ msc_ver> 1300

// This is Visual C ++. NET 2002

# Endif

02) # nuances between else if and # Elif

# If _ msc_ver <1202

// EVC 4.0 complier is cross 1200-1202

# Else if _ msc_ver> = 1400

// Visual c ++ 2005 complier is 1400

# Else

// Visual c ++ 2005 complier is 1400

# Endif

This pre-compiled code will cause an error in evc4.0 and Visual Studio 2005 compilation, and the error message is "unexpected # else". In this case, you only need to replace "# else if" with "# Elif:

# If _ msc_ver <1202

// EVC 4.0 complier is cross 1200-1202

# Elif _ msc_ver> = 1400

// Visual c ++ 2005 complier is 1400

# Else

// Visual c ++ 2005 complier is 1400

# Endif

The above code can be compiled successfully.

03) a header file containing the parent directory

If the current file needs to contain a header file in the upper-level directory, you can use the ".. \" format, for example:

# Include ".. \ Configure. H"

It can even be located in the upper-level directory through recurrence:

# Include ".. \ Configure. H"

04) include the header file under a folder in the current directory

If the current file needs to contain a header file in a folder in the current directory, it can be in the form of ". \", for example:

# Include ". \ include \ Configure. H"

05) determine the current CPU type

# Ifdef _ x86 _

// X86

# Endif

# Ifdef _ MIPS _

// MIPS

# Endif

# Ifdef _ arm _

// Arm

# Endif

06) manually add the Lib Library to the code

# Pragma comment (Lib, ".. \ engine. lib ")

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.