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 14:41:26 -0800 Organization: None to speak of Lines: 54 Message-ID: <87tswz3co9.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> <10jgp66$31gp5$1@nntp.eternal-september.org> <10jgusa$2rp4s$3@nntp.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 05 Jan 2026 22:41:28 +0000 (UTC) Injection-Info: nntp.eternal-september.org; posting-host="ebc97b9c3a668ec2b2ce4c7b48f9769f"; logging-data="3445363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185ys+4cB/zpgCpKFIDiYBX" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:FyKWU50C7PVD27Jflodk/k5LFLI= sha1:5AhMGaz1z12YsYEFe7pogWIFIvQ= Xref: csiph.com comp.lang.c:396191 James Kuyper writes: > On 2026-01-05 11:34, David Brown wrote: > ... >> As I understand it, time_t is intended to be suitable for holding a >> number of seconds ... > > The standard says nothing about that. > >> ... (it is used for that purpose in struct timespec). ... > > The standard says nothing to connect time_t to struct timespec. Yes, but also no. struct timespec contains at least the following members, in any order: time_t tv_sec; // whole seconds — ≥ 0 long tv_nsec; // nanoseconds — [0, 999999999] But a footnote says: The tv_sec member is a linear count of seconds and may not have the normal semantics of a time_t. This makes for a simpler implementation *if* the time_t value returned by time(), and operated on by difftime(), mktime(), ctime(), gmtime(), and localtime(), happens to hold a linear count of seconds (as it does on most systems). It's odd that time_t is used for two potentially very different purposes, one as a member of struct timespec and another as used in all other contexts. And I would guess that a lot of code that uses struct timespec *assumes* that its time_t member has the same semantics value returned by time(NULL). For example, as I write this the time is 2026-01-05 22:32:57.881 UTC. The corresponding value returned by time() is 1767652377 (seconds since the 1970 epoch, no milliseconds). An implementation could represent the current time (the value returned by time(NULL) as a 64-bit integer with the value 20260105223257881. But timespec_get() would still have to set the tv_sec member to 1767652377. It might have been cleaner either to require that time_t represents a count of seconds, or to use a type other than time_t for the tv_sec member of struct timespec. I know there are systems that use something other than seconds since 1970 in the underlying time representation, but are there any C implementations that don't use seconds since 1970? (POSIX and Windows both specify that.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */