The ansi c standard has several predefined macros: __file _ date _ time ___ _ line _.
_ Line __: inSource codeInsert Current SourceCodeRow number;
_ File __: insert the name of the current source file into the source file;
_ Date __: Insert the current compilation date into the source file
_ Time __: Insert the current compilation time into the source file;
_ Stdc __: when requiredProgramWhen the ansi c standard is strictly followed, this identifier is assigned a value of 1;
_ Cplusplus: This identifier is defined when a C ++ program is compiled.
These macros are useful ~~~~~~~~
When debugging a program or compiling a program, __line _ is useful. It can be used to print the line numbers of logical errors ~~~~~~~, Example:
Switch (X)
{
Case 1:
....;
Break;
Case 2:
.....;
Break;
Default:
Printf ("logic erro line number % d! /N ",__ line __);
Break;
}
Another example is to use _ date _ and _ time _ to insert the Compilation Time.
Code:
Void print_version_info (void)
{
Printf ("date compiled: % s/n" ,__ date __);
Printf ("timecompiled: % s/n" ,__ time __);
}
Output Format: Mm dd yy and HH: mm: SS
In this way, you can implement version control and know when you have compiled it ~~