Is the __TIME__ preprocessor macro guaranteed to be constant in a file?

Just out of curiosity, I wonder if the value set by the standard __TIME__ preprocessor macro __TIME__ be changed within a single translation unit?

In other words, __TIME__ is determined once during preprocessing, and then committed or revised each time it occurs?

If this is not specified by the C standard, is there a standard de facto behavior among the main implementations (gnu, clang, intel, msvc)?

+7
c macros c-preprocessor
source share
1 answer

C does not strictly indicate that "translation time" is constant during preprocessing / compilation.

My experience was constant. But since this is only the second, for this compilation it is necessary to cross the second border in order to differentiate.

__TIME__ Translation time of the preprocessor translation unit: character string literal of the form "hh:mm:ss" , as in the time generated by asctime . If the transfer time is not available, a specific lead time must be provided. C11 Β§6.10.8.1 1

Definitions for __DATE__ and __TIME__ , when, respectively, the date and time of the transfer is not available (6.10.8.1). (Informative) C11 Β§J.3.11 1

+5
source share

All Articles