Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Just out of curiosity I am wondering whether the value given by the standard __TIME__ preprocessor macro can change within a single translation unit?

In other words, is __TIME__ determined once during preprocessing and then fixed, or is it re-evaluated each time it is encountered?

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

like image 615
marack Avatar asked Apr 27 '16 22:04

marack


People also ask

Are macros preprocessor?

The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled. These transformations can be the inclusion of header files, macro expansions, etc.

What are pre defined macros?

Predefined Macros in C99 standard:It is used to test whether a header is compiled by a C compiler or a C++ compiler. This macro gives value similar to __STDC_VERSION__, in that it expands to a version number.


Video Answer


1 Answers

C does not rigorously specify the the " time of translation" is constant throughout a pre-processing/compilation.

My experience has been it is constant. But since it is only to the second, a given compilation would need to cross a second boundary to differ.

__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

like image 69
chux - Reinstate Monica Avatar answered Oct 19 '22 07:10

chux - Reinstate Monica