Predefined macros in Visual C + +

Source: Internet
Author: User

I. MAIN objectives

(because Visual Studio typically contains many development environments, it is commonly referred to as Visual C + + 20xx)

Organize the predefined macros under Visual C + + 2010. To do a memo and understand, in the actual coding can consider using some of the macro as a criterion.

Main reference Links: Http://msdn.microsoft.com/en-us/library/b0084kay (v=vs.100). aspx

Second, VC + + 2010 pre-defined macros

Note All of the predefined macros that are mentioned in this article are parameterless and cannot be redefined.

1. __file__, __line__

These two scheduled macros are defined in the C language and are used primarily to identify the source file name (full path or file name) where the code snippet resides, and the number of rows in the source file where the current location is located. Used for error tracking, pre-compilation errors, program exception tracking, such as Trace, Assert failed to prompt information.

2. _char_unsigned

Additional defined macros in the VC. Used primarily to describe data of type char, whether it is signed or unsigned. By default, char is unsigned.

In many open source projects, using CL or GCC to compile the source code may need to focus on the positive and negative of Char: Because the signed char in the case of a value run encounters a type promotion may have the behavior of uncertainty (related to compiler implementation).

3. __funcdname__,__funcsig__,__function__

The macros defined in the VC. Valid only for use in function implementations. Three macros are represented by the compiler's decorated function name, function signature, and function name in code.

The actual use can refer to the following code:

voidexamplefunction () {printf ("Function Name:%s\n", __function__); printf ("decorated function name:%s\n", __funcdname__); printf ("Function Signature:%s\n", __funcsig__); //VC + + 2010 of the actual output// -------------------------------------------------    //Function name:examplefunction//decorated function Name: [email protected] @YAXXZ//Function signature:void __cdecl examplefunction (void)}
View Code

4. _win32, _win64

The macros defined in the VC. Used to indicate that the application is based on the Win32 or Win64 platform.

5. _debug

The macros defined in the VC. The implication is that it is clear that the current program is a debug version.

Because _DEBUG and debug two macros are often mixed together, it's easy to misunderstand which one to use.

As described and explained on MSDN, almost most of the data is only _DEBUG macros, which are macros that must be defined for the Assert, Trace, and so on.

So where does the macro from debug come from? MFC programs are usually defined with a debug macro. You can find an MFC project in the source code file, enter #ifdef DEBUG, and then go to the definition to see its implementation. In Atldef.h, you will see the following definition:

#ifdef _debug#ifndef DEBUG #define DEBUG#endif#endif

This is the more obvious. is a predefined macro in MFC that feels like it is preventing users from using it incorrectly.

Therefore, you should use the _DEBUG macro in the actual encoding, and do not use debug (even if it is already defined).

Predefined macros in Visual C + +

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.