On the other hand, the C + + compiler will have several macros built into it, which not only helps us to complete the cross-platform source code, but also subtly helps 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.
#include <stdio.h>intMainvoid) { intanswer; //__date__, __time__, __file__, __line__ for pre-defined macrosprintf"Date:%s\n", __date__); printf ("Time :%s\n", __time__); printf ("File:%s\n", __file__); printf ("Line :%d\n", __line__); printf ("Enter 1 or 0:"); scanf ("%d", &answer); //This is a conditional expressionprintf"%s\n", answer?"You said YES":"You said NO");}
Several pre-defined macros for C + +: __date__,__time__,__file__,__line__