I use the __DATE__
macro for getting a compile-time year:
const QString build_year = __DATE__ + 7;
The Clang Code Model in QtCreator throws a -Wdate-time
warning for using the __DATE__
macro.
warning: expansion of date or time macro is not reproducible
I can disable this warning with -Wno-date-time
, but what is wrong with using __DATE__
?
What is an "expansion" of the macro, how can it be "reproducible" or "not reproducible", and why is "not reproducible" bad?
Similarly, the __TIME__ macro is used to insert the current compilation time in the form "hh:mm:ss" into your program. This date-and-time-stamp feature should not be confused with the current system date and time. Rather, these two macros enable you to keep track of the date and time your program was last compiled.
Thank You for your Questions.... _DATE_ macro expands to a string constant that describes the date on which the pre-processor is being run whereas _TIME_ macro expands to a string constant that describes the time at which the pre-processor is being run. Thanks, Team DishaaPro
__DATE__ This macro expands to a string constant that describes the date on which the preprocessor is being run. The string constant contains eleven characters and looks like "Feb 12 1996". __TIME__ This macro expands to a string constant that describes the time at which the preprocessor is being run.
Having repeated builds reproduce binary-identical outputs is desirable from many points of view. Building identical source code from identical tool chains giving different binaries each time could hide serious problems.
If you don't need to produce identical binaries every time you build identical code just disable that warning. that's why the command-line switch exists.
The warning message tells you why. Using the macro does not result in a reproducible build since its value will change over time. A build in 2018 and one in 2019 will not produce the same binary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With