Compiler built-in macros:
We first introduce several compiler built-in macro definitions, these macro definitions can not only help us to complete the cross-platform source code writing, flexible use can also skillfully help us to output very useful debugging information.
There are several standard scheduled macros (also commonly used) in the ANSI C standard:
__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.
The following example:
[CPP]View Plaincopy
- #include <stdio.h>
- int main ()
- {
- Char file[16];
- Char func[16];
- int line;
- sprintf (file,__file__); //File name
- sprintf (func,__function__); //Function name
- printf ("file=%s\n", file);
- printf ("func=%s\n", func);
- printf ("%05d\n", __line__); Line number
- return 0;
- }
C++/C Get CPP file line number with file name