微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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 …的标准文本

原文地址:https://www.jb51.cc/c/111806.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐