我有以下小程序:
#include <iostream>
int main() {
std::cout << "Time: " << __TIME__ << std::endl;
std::cout << "Timestamp: " << __TIMESTAMP__ << std::endl;
return 0;
}
产生以下输出:
如你所见,__TIME__
与__TIMESTAMP__
有相当大的区别,提前了4秒 .
为什么会这样?这两个时间怎么会有这么大的差异?
即使程序的构建时间不到 4 秒,那么这种差异从何而来?
最佳答案
这两个宏做完全不同的事情:
海合会
__TIME__
This macro expands to a string constant that describes the time at which the preprocessor is being run. The string constant contains eight characters and looks like "
23:59:01
". If GCC cannot determine the current time, it will emit a warning message (once per compilation) and__TIME__
will expand to "??:??:??
".
( source )
__TIMESTAMP__
This macro expands to a string constant that describes the date and time of the last modification of the current source file. The string constant contains abbreviated day of the week, month, day of the month, time in hh:mm:ss form, year and looks like "
Sun Sep 16 01:03:52 1973
". If the day of the month is less than 10, it is padded with a space on the left.If GCC cannot determine the current date, it will emit a warning message (once per compilation) and
__TIMESTAMP__
will expand to "??? ??? ?? ??:??:?? ????
".
( source )
Visual Studio
__TIME__
: The most recent compilation time of the current source file. The time is a string literal of the form hh:mm:ss.
__TIMESTAMP__
: The date and time of the last modification of the current source file, expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, where Ddd is the abbreviated day of the week and Date is an integer from 1 to 31.
( source )
关于c++ - 哪个宏更准确? __TIME__ 还是 __TIMESTAMP__?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27691101/