Pre-defined Macros in visual c ++
I. Main Objectives
(Because visual studio usually contains many development environments, c/c ++ ide is usually called visual c ++ 20xx)
Sort out the predefined Macros in visual c ++ 2010. Let's take a look at the preparation and understanding. In actual coding, we can consider using some macros as the judgment standard.
Http://msdn.microsoft.com/en-us/library/b0084kay (v = vs.100). aspx
Ii. predefine Macros in vc ++ 2010
Note that all the predefined macros mentioned in this article have no parameters and cannot be redefined.
1. _ FILE _, _ LINE __
These two predefined macros are defined in C language and are mainly used to identify the source file name (full path or file name) where the code snippet is located and the number of lines in the source file at the current position. It is often used for Error Tracking, pre-compilation Error Reporting, program exception tracking, and so on, such as TRACE and ASSERT failure prompts.
2. _ CHAR_UNSIGNED
Add the defined macro to vc. It is mainly used to describe data of the char type, whether it is signed or unsigned. By default, char is unsigned.
In many open-source projects, when using cl or gcc to compile the source code, you may need to pay attention to the plus and minus signs of char: this is because there may be uncertain behaviors in the case that a signed char encounters a type improvement during numerical operation (related to the implementation of the compiler ).
3. _ FUNCDNAME _, _ FUNCSIG _, and _ FUNCTION __
The macro defined in vc. Valid only in function implementation. The three macros indicate the function name, function signature, and function name in the Code modified by the compiler.
For actual use, refer to the following code:
Void exampleFunction () {printf ("Function name: % s \ n", _ FUNCTION _); printf ("Decorated function name: % s \ n ", _ FUNCDNAME _); printf ("Function signature: % s \ n", _ FUNCSIG __); // actual output of vc ++ 2010 // ----------------------------------------------------- // Function name: exampleFunction // Decorated function name :? ExampleFunction @ YAXXZ // Function signature: void _ cdecl exampleFunction (void )}View Code
4. _ WIN32, _ WIN64
The macro defined in vc. It indicates that the application is based on win32 or win64 platform.
5. _ DEBUG
The macro defined in vc. It indicates that the current program is a debugging version.
The reason is that _ DEBUG and DEBUG macros are often mixed together, so it is easy to misunderstand which one should be used.
According to the description and description on msdn, almost all documents only have _ DEBUG macros, which are also macros that must be defined for assert and TRACE to take effect.
So where does the DEBUG macro come from? The MFC program usually uses the DEBUG macro definition. You can find a source code file in the mfc project, enter # ifdef DEBUG, and go to the definition to see its implementation. In atldef. h, the following definition is displayed:
#ifdef _DEBUG#ifndef DEBUG#define DEBUG#endif#endif
This is more obvious. It is a pre-defined macro in mfc. I personally feel like it is intended to prevent users from mistakenly using it.
Therefore, the _ DEBUG macro should be used in actual encoding, rather than DEBUG (even if it is already defined ).