Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: printf and time_t Date: Tue, 03 Feb 2026 17:19:10 -0800 Organization: A noiseless patient Spider Lines: 56 Message-ID: <86ikcdi9v5.fsf@linuxsc.com> References: <10jfol6$2u6r8$1@news.xmission.com> <10jgdu9$2t8dh$1@nntp.eternal-september.org> <10jhkso$3c9r2$3@nntp.eternal-september.org> <20260106112938.00004446@yahoo.com> <10jj9st$3jbe4$2@dont-email.me> <20260106200522.000015ea@yahoo.com> <87h5sy2rlb.fsf@example.invalid> <87qzs1gliq.fsf@example.invalid> <20260108012620.000041a9@yahoo.com> <87bjj5gei4.fsf@example.invalid> <20260108023846.0000260c@yahoo.com> <10jpi8h$15aea$1@dont-email.me> <20260109141859.00004f22@yahoo.com> <10jv3rb$15aea$2@dont-email.me> <20260111132015.000026ad@yahoo.com> <87ikd82tks.fsf@example.invalid> <20260111153201.000075f9@yahoo.com> <87ecnv3gj2.fsf@example.invalid> <10k27e7$25sqv$1@dont-email.me> <87qzrvow2l.fsf@example.invalid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Wed, 04 Feb 2026 01:19:13 +0000 (UTC) Injection-Info: dont-email.me; posting-host="30e2bd46efc1ceede85686db5fb0dc7e"; logging-data="2073871"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19J9cSoFGb0bmFXoeyiohq7uiWanb28Kbk=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:82f9ydIWNsXNSskGSjT5VhBg2Zs= sha1:fGHooe1mhIyM53BEUHmCSUW1wQg= Xref: csiph.com comp.lang.c:396583 Keith Thompson writes: > David Brown writes: > [...] > >> C23 includes length specifiers with explicit bit counts, so "%w32u" is >> for an unsigned integer argument of 32 bits: >> >> """ >> wN Specifies that a following b, B, d, i, o, u, x, or X conversion >> specifier applies to an integer argument with a specific width >> where N is a positive decimal integer with no leading zeros >> (the argument will have been promoted according to the integer >> promotions, but its value shall be converted to the unpromoted >> type); or that a following n conversion specifier applies to a >> pointer to an integer type argument with a width of N bits. All >> minimum-width integer types (7.22.1.2) and exact-width integer >> types (7.22.1.1) defined in the header shall be >> supported. Other supported values of N are implementation-defined. >> """ >> >> That looks to me that it would be a correct specifier for uint32_t, > > Yes, so for example this: > > uint32_t n = 42; > printf("n = %w32u\n", n); > > is correct, if I'm reading it correctly. It's also correct for > uint_least32_t, which is expected to be the same type as uint32_t > if the latter exists. There's also support for the [u]int_fastN_t > types, using for example "%wf32u" in place of "%w32u". > >> and should also be fully defined behaviour for unsigned int and >> unsigned long if these are 32 bits wide. > > No, I don't think C23 says that. Right, it doesn't. > If int and long happen to be the same > width, they are still incompatible, and there is no printf format > specifier that has defined behavior for both. > > That first sentence is a bit ambiguous > > wN Specifies that a following b, B, d, i, o, u, x, or X conversion > specifier applies to an integer argument with a specific width ... > > but I don't think it means that it must accept *any* integer type > of the specified width. As I read the standard there is no ambiguity. The first sentence says what the length modifier means. The second sentence says which types (if any) correspond to the description in the first sentence.