What are the _ _DATE_ _ and _ _TIME_ _ preprocessor commands?
The _ _DATE_ _ macro is used to insert the current compilation date in the form “mm dd yyyy” into your
program. Similarly, the _ _TIME_ _ macro is used to insert the current compilation time in the form
“hh:mm:ss” into your program. This date-and-time-stamp feature should not be confused with the current
system date and time. Rather, these two macros enable you to keep track of the date and time your program
was last compiled. This feature can come in very handy when you are trying to track different versions of your
program. For instance, many programmers like to put a function in their programs that gives compilation
information as to when the current module was compiled. This task can be performed as shown here:
program. Similarly, the _ _TIME_ _ macro is used to insert the current compilation time in the form
“hh:mm:ss” into your program. This date-and-time-stamp feature should not be confused with the current
system date and time. Rather, these two macros enable you to keep track of the date and time your program
was last compiled. This feature can come in very handy when you are trying to track different versions of your
program. For instance, many programmers like to put a function in their programs that gives compilation
information as to when the current module was compiled. This task can be performed as shown here:
#include <stdio.h>
void main(void);
void print_version_info(void);
void main(void)
{
print_version_info();
}
void print_version_info(void)
{
printf(“Date Compiled: %s\n”, _ _DATE_ _);
printf(“Time Compiled: %s\n”, _ _TIME_ _);
}
}
void print_version_info(void)
{
printf(“Date Compiled: %s\n”, _ _DATE_ _);
printf(“Time Compiled: %s\n”, _ _TIME_ _);
}
In this example, the function print_version_info() is used to show the date and time stamp of the last time
this module was compiled.
Cross Reference:
V.18: What are the standard predefined macros?
V.19: How can a program be made to print the line number where an error occurs?
V.20: How can a program be made to print the name of a source file where an error occurs?
V.21: How can you tell whether a program was compiled using C versus C++?
No comments:
Post a Comment