我想执行a printf()来显示上次编译当前正在执行的代码的时间.C/C++是否提供了一个宏,可以让您在编译期间解析为时间戳?
想要使用__ DATE __和__ TIME __作为整数,以便在编译时为我的代码提供自动化版本.
#define STRINGIZER(arg) #arg
#define STR_VALUE(arg) STRINGIZER(arg)
#define DATE_as_int_str useD(__DATE__) // What can be done ?
#define TIME_as_int_str useT(__TIME__) // What can be done ?
#define VERSION 1.4
#define COMPLETE_VERSION STR_VALUE(VERSION) "." DATE_as_int_str "." TIME_as_int_str
Run Code Online (Sandbox Code Playgroud)
并获得COMPLETE_VERSION一个字符串const unsigned char [].
const unsigned char completeVersion[] = ?? COMPLETE_VERSION;
Run Code Online (Sandbox Code Playgroud)
应输出1.4.1432.2234的东西.
其中一个可能的解决方案可能是但不起作用:convert - date -to-unsigned-int
在编译时的上下文中,convertint-date-and-time-string-to-just-integers-in-c 可以参考expand-and-stringification-how-to-get-the-marco-name-not-its-value