c – 编译时可以获得时间(当天)和日期吗?

在编译时可以通过时间和日期(BUILDTIME)知道在二进制文件(可执行文件/库)中以可移植的方式将有关创建时刻的信息纳入其中?

我们目前有一个使用sh.exe的解决方案,并且需要在Windows下安装msys,但是我想知道是否可以在没有它的情况下执行.

搜索“建立时间/日期”,“编译时间/日期”等内容并没有产生任何相关的结果.

编辑:

当我知道__TIME__时,可能会发现这个问题以前被问过:Recording the time when you compile a source

解决方法

标准宏__DATE__和__TIME__宏完成了这项工作.

请注意,这将为您提供使用它们的文件的编译日期.不是链接日期.因此,您必须在每次构建文件时触摸文件,或在MSVC中执行预构建步骤.

The C99 standard says

6.10.8 Predefined macro names

The following macro names shall be defined by the implementation:

  • __DATE__: The date of translation of the preprocessing translation unit: a character string literal of the form “Mmm dd
    yyyy”,where the names of the months are the same as those generated
    by the asctime function,and the first character of dd is a space
    character if the value is less than 10. If the date of translation is
    not available,an implementation-defined valid date shall be supplied.
  • __TIME__: The time of translation of the preprocessing translation unit: a character string literal of the form “hh:mm:ss” as
    in the time generated by the asctime function. If the time of
    translation is not available,an implementation-defined valid time
    shall be supplied.

在这里复制了C99文本,但是这些宏比C99要老得多…我没有设法找到旧的C …的标准文本

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...