Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How to fix warning: [-Wdate-time] Date: Mon, 17 Apr 2017 09:25:07 -0700 Organization: None to speak of Lines: 88 Message-ID: References: <8e289215-369a-43c5-aa46-9428ad81a224@googlegroups.com> <195fbe3a-b69c-45e4-ac6e-a45a1913a834@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="6ede04a56392f1431524e35eef643cab"; logging-data="16572"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18at4EUS+beHddfCla/qhKX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:/4NVxUexg6V0KB8vvr00LTmDjG4= sha1:3c5oRASziQ1ByAxErqxNRpPfLkk= Xref: csiph.com comp.lang.c:108218 Ken Brody writes: > On 4/16/2017 2:44 PM, supercat@casperkitty.com wrote: >> On Saturday, April 15, 2017 at 5:02:05 PM UTC-5, Keith Thompson wrote: >>> The problem would be that the expansions of __DATE__ and __TIME__ would >>> be whatever was passed on the compiler command line and not, as the >>> standard specifies and a reader will assume, the date and time of >>> translation. >> >> The Standard does not require any particular degree of precision, nor does >> it specify the means via which an implementation would determine the time. >> There is no requirement that platforms which host C compilers need to have >> any kind of real-time clock functionality. If a compiler included a >> command-line option to say "Don't trust the system clock--the time is >> actually 1989-06-05 04:32:10, I don't think the Standard would require that >> the compiler not believe the command line. > > NB: I am in no way a "language lawyer". > > Looking at N1256 (yes, I know it's not the latest, but it's the latest I > have on this computer), section 6.10.8 says this about __DATE__: > > "If the date of translation is not available, an implementation-defined > valid date shall be supplied." > > A similar statement is made about __TIME__. > > Without a detailed explanation of what "is not available" means, you could > easily say that "using compiler flag X will cause the compiler to behave as > if the date and time are not available" is still conforming. IMHO, the requirement that the date "is not available" is not satisfied by an option that tells the compiler to *pretend* the date is not available. I'd say that a compiler with that option specified is non-conforming, simply because it violates the standard's reasonably clear requirements for __DATE__ and __TIME__. [...] > Also, what happens if the computer/compiler isn't that fast, and the file > takes more than a second to preprocess? Can __TIME__ at the top of the file > be different than at the bottom of the file? The standard is less than crystal clear on this point, but I'd say that a conforming implementation could have __TIME__ and __DATE__ have different values within a source file. For that matter, suppose a source file refers to __DATE__ and __TIME__ on the same line: printf("%s %s\n", __DATE__, __TIME__); It's possible that the expansion of __DATE__ could be determined just before midnight, and the expansion of __TIME__ just after midnight (or vice versa) resulting in a printed date and time that appear to be off by 24 hours. > Finally, can the time be available at the top of the file, but not at the > bottom? (Consider, for example, a hardware clock that for some reason fails > during the compile. Or maybe your internet connection to nist.gov goes down.) Possibly. > I would expect that any non-DS9K compiler would simply get the date/time at > the start of the compile, and keep using that throughout the compile. But > that doesn't mean the Standard requires it. GNU cpp (used by gcc) appears to compute the expansion of __DATE__ and __TIME__ once per translation unit, when one of the macros is encountered for the first time. I just took a look at the GNU cpp manual. For __DATE__, it says: If GCC cannot determine the current date, it will emit a warning message (once per compilation) and '__DATE__' will expand to '"??? ?? ????"'. This contradicts the standard, which says: If the date of translation is not available, an implementation-defined valid date shall be supplied. Likewise for __TIME__. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"