从不同文件调用时,C ++ __TIME__是不同的 [英] C++ __TIME__ is different when called from different files

查看:87
本文介绍了从不同文件调用时,C ++ __TIME__是不同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在玩预定义的宏时遇到了这个奇怪的事情. 因此,基本上,从不同文件调用__TIME__时,会发生以下情况:

I encountered this strange thing while playing around with predefined macros. So basically, when calling __TIME__ from different files, this happens:

反正我可以解决这个问题吗?还是为什么会发生这种情况?
我所做的只是来自不同来源的不同功能的printf("%s\n", __Time__);.

Is there anyway I can fix this? Or why does this happen?
All I am doing is printf("%s\n", __Time__); from different functions in different sources.

推荐答案

还是为什么会这样?

Or why does this happen?

从文档中

此宏扩展为一个字符串常量,用于描述预处理器的运行时间.

如果源文件在不同的时间编译,那么时间将不同.

If source files are compiled at different times, then the time will be different.

反正我可以解决这个问题吗?

Is there anyway I can fix this?

您可以使用命令行工具生成时间字符串,并将该字符串作为宏定义传递给编译器.这样,该命令编译的所有文件的时间将相同.

You could use a command line tool to generate the time string, and pass the string as a macro definition to the compiler. That way the time will be the same for all files compiled by that command.

这篇关于从不同文件调用时,C ++ __TIME__是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆