__TIME__ 预处理器宏是否保证在文件中保持不变?

Is __TIME__ preprocessor macro guaranteed to be constant within a file?

出于好奇,我想知道标准 __TIME__ 预处理器宏给出的值是否可以在单个翻译单元内更改?

也就是说__TIME__是在预处理的时候判断一次然后固定,还是每次遇到都重新判断?

如果 C 标准没有指定,主要实现(gnu、clang、intel、msvc)之间是否有事实上的标准行为?

C 没有严格指定“翻译时间”在整个 pre-processing/compilation.

中是恒定的

我的经验是它是不变的。但是因为它只是第二个,给定的编译需要跨越第二个边界才能有所不同。

__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. C11 §6.10.8.1 1

The definitions for __DATE__ and __TIME__ when respectively, the date and time of translation are not available (6.10.8.1). (Informative) C11 §J.3.11 1