At the time of writing the program, always more or less will add some of the printf and other statements for output debugging information, but the printf statement has a very inconvenient place is when we need to publish a program to be a piece of the statement to delete these statements, and once again to debug the time, These statements have to add, which brings us a lot of inconvenience, wasting our time, but also caused the inefficient commissioning. Therefore, many people choose to use the macro definition to output the debug statements.
Compiler built-in macros, the ANSI C standard has several standard scheduled macros (also commonly used):
__line__: Inserts the current source code line number in the source code;
__file__: Inserts the current source filename in the source file;
__date__: Insert the current compilation date in the source file
__time__: Inserts the current compile time in the source file;
__stdc__: The identifier is assigned a value of 1 when the program strictly complies with the ANSI C standard;
__cplusplus: This identifier is defined when you write a C + + program.
Test Source:
#include "stdafx.h" #ifdef _DEBUG #define DEBUG (format,...) printf ("File:" __file__ ", Line:%05d:" format "\ n", __line__, # #__VA_ARGS__) #else #define DEBUG (format,...) #endif//!_debug int _tmain (int argc, _tchar* argv[]) { DEBUG ("File line Test%d", 1); return 0;}
Test Results:
__FILE__,__LINE__ Output Debugging Information