This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377D: 关于当前时间获取的问题

Part Number: TMS320F28377D

请问为什么用__DATE__和__TIME__获取的时间不是当前编译的版本时间,而是首次编译的日期?

  • Hi July,

    我询问资深工程师后回复您

  • 这些预定义宏给出的时间和日期是当前日期和时间。 这是一种查看方式:

    C:\examples>type file.c
    char *test()
    {
       return __TIME__;
    }
    
    C:\examples>cl2000 --gen_preprocessor_listing file.c
    
    C:\examples>type file.rl
    L 1 "file.c"
    Nchar *test()
    N{
    N   return __TIME__;
    X   return "09:39:30";
    N}
    
    C:\examples>cl2000 --gen_preprocessor_listing file.c
    
    C:\examples>type file.rl
    L 1 "file.c"
    Nchar *test()
    N{
    N   return __TIME__;
    X   return "09:39:36";
    N}

    此示例显示了使用 __TIME__ 的简单测试函数的源代码。 然后它使用选项 --gen_preprocessor_listing 构建它。 要了解有关此选项的更多信息,请在 C28x compiler manual中搜索它。 重要的细节是它创建了 file.rl,普通源代码的行以 N 开头,带有 X 的行是在扩展像 __TIME__ 这样的宏之后出现的。 该示例构建了两次。 您可以看到它们相隔 6 秒构建。 这表明 __TIME__ 随着编译时间的变化而变化。

    如果您看到不同的行为,请以类似的方式进行演示。

  • 客气了。如果觉得有帮助到您的话,请点击绿色按钮确认答案,方便其他工程师参考,谢谢