__DATE__ preprocessor macros

__DATE__ preprocessor macros


__DATE__ is a preprocessor macro in C language, it will be replaced by a string constant at compile time, indicating the date when the current source file was compiled. The format of the string is "MMM DD YYYY", where MMM represents the abbreviation of the month (such as Jan, Feb, Mar, etc.), DD represents the number of days, and YYYY represents the year. For example, on June 1, 2023, __DATE__ would be replaced with "Jun 01 2023".

__DATE__Usually used to record compilation time and date in a program, or to display version information in program output. For example, here is a __DATE__sample code that uses macros to display compile time and version information:

#include <stdio.h>

int main() {
    
    
    printf("This program was compiled on %s, version 1.2.3\n", __DATE__);
    return 0;
}

In the above code, __DATE__the macro is used to output the compilation time and version information of the program. When the program is compiled, __DATE__it will be replaced with the current date string, and the output will be similar to "This program was compiled on Jun 01 2023, version 1.2.3".

Guess you like

Origin blog.csdn.net/qq_44678607/article/details/130922745