Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: printf and time_t Date: Mon, 05 Jan 2026 15:04:22 -0800 Organization: None to speak of Lines: 41 Message-ID: <87pl7n3bm1.fsf@example.invalid> References: <10jfol6$2u6r8$1@news.xmission.com> <10jfs23$2liif$1@dont-email.me> <20260105105138.00005f0a@yahoo.com> <10jgohd$31ebg$1@nntp.eternal-september.org> <20260105192351.00001903@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Mon, 05 Jan 2026 23:04:24 +0000 (UTC) Injection-Info: nntp.eternal-september.org; posting-host="ebc97b9c3a668ec2b2ce4c7b48f9769f"; logging-data="3445363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++DXsrb8RiqY4sXx8K22wP" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:d5rk20CFA3vHhHMpmlGIdfCaZuo= sha1:gUjPwytvxrPwSHZlfpwiL6ffnSc= Xref: csiph.com comp.lang.c:396192 Michael S writes: > On Mon, 5 Jan 2026 16:23:09 -0000 (UTC) > Lew Pitcher wrote: [...] >> As Andrey pointed out, time_t can resolve to a floatingpoint type, >> so, "long long" would go wrong if the implementation typedefs it to >> float, or >> double, or >> long double. > > Reading literally what you wrote makes no sense, so I assume that you > meant that 'it' above constitutes time_t rather than 'long long'. > > The rest of the post assumes 64-bit 'long long'. > 'typedef float time_t' where float==IEEE binary32 is a bad idea, because > you lose your 1sec resolution after 7 months. I.e. with Unix epoch you > lost it a year or two before Ritchi finished his first C compiler. > 'typedef double time_t' means that you lost 1 sec resolution ~3 > orders of magnitude before you got a chance to overflow 'long long'. > > Only in case of 'typedef long double time_t' there is a chance that > overflow happens before resolution is lost. But barely so for 80-bit > long double format prevalent on i386/AMD64 computers. Assuming IEEE floating-point, and assuming time_t represents seconds since the usual 1970 epoch, the current resolution of a 64-bit floating-point time_t would be about 238 nanoseconds. It has that same resolution for any time from 2004-01-10 to 2038-01-18. (The resolution doubles when the number of seconds since 1970 exceeds a power of 2.) The resolution doesn't reach one second until 142715360-12-05 (that's a Friday if we're still using the same calendar). I don't suggest that using type double for time_t would be a good idea, and in fact POSIX requires time_t to be an integer type. (I think Windows does as well, but the documentation is less clear, or perhaps I'm missing something.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */