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: Fri, 06 Feb 2026 02:59:01 -0800 Organization: A noiseless patient Spider Lines: 108 Message-ID: <86wm0qgmtm.fsf@linuxsc.com> References: <10jfol6$2u6r8$1@news.xmission.com> <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> <86zf6kkjw0.fsf@linuxsc.com> <20260111235104.00001463@yahoo.com> <86ms1pj0bc.fsf@linuxsc.com> <10ltjjt$1o4pk$1@dont-email.me> <865x8cio5y.fsf@linuxsc.com> <10lvt1s$2fu8f$1@dont-email.me> <10lvul0$2gps1$1@dont-email.me> <10m024m$2hqvi$1@dont-email.me> <10m091i$2kiff$1@dont-email.me> <10m0b0g$2l6li$1@dont-email.me> <10m1vl7$35irp$1@dont-email.me> <87wm0r80zj.fsf@example.invalid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 06 Feb 2026 10:59:05 +0000 (UTC) Injection-Info: dont-email.me; posting-host="0212364931b71f18d3f23c70ceb29fbc"; logging-data="79087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cSccM+MPUqKbnVvpVcLAHQQqtvbyqUaM=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:5dW96auGvrOOoWH1ljqLHSksoIY= sha1:MQQudlLLoUXiPk7Oy6JG9af1TJc= Xref: csiph.com comp.lang.c:396618 Keith Thompson writes: > David Brown writes: > [...] > >> How many people do you know who have actually written and use a >> C11 print system using _Generic and variadic macros? I don't know >> any. (I've written simple examples as proofs of concept, posted >> in this group, but not for real use.) It turns out that people >> /don't/ have to have workarounds. "printf" has its limitations - >> there's no doubt there. But it is good enough for most people >> and most uses. > > I recently played around with an attempted framework using _Generic. > The goal was to be able to write something like > > print(s(x), s(y), s(z)); > > where x, y, and z can be of more or less arbitrary types (integer, > floating-point char*). The problem I ran into was that only one of > the generic associations is evaluated (which one is determined at > compile time), but *all* of them have to be valid code. That is annoying but it shouldn't be too hard to work around it. To verify that hypothesis I wrote this test case: #include #include #include #include "h/show.h" int main(){ unsigned long long ull = -1; signed long long sll = -1; unsigned long ul = -1; signed long sl = -1; unsigned char uc = -1; signed char sc = -1; unsigned short us = -1; signed short ss = -1; unsigned int ui = -1; signed int si = -1; char c = 'q'; float f = 1.23; double d = 3.14159265358979312; double long ld = 6.28318530717958623; _Bool yes = 1; _Bool no = !yes; clock_t runtime = clock(); time_t now = time(0); off_t offset = 27; uint16_t u16 = -1; int16_t s16 = -1; uint_least32_t uge32 = -1; int_least32_t sge32 = -1; uint_fast32_t uf32 = -1; int_fast32_t sf32 = -1; char * foo = "foo"; const char * bas = "bas"; show( uc,sc,us,ss,ui,si,ul,sl,ull,sll, c,f,d,ld,yes,no,u16,s16,uge32,sge32, runtime,now,offset,uf32,sf32, c * now / 1e8 * ld, foo, bas ); printf( "\n" ); return 0; } which compiles under C11 and (along with the show.h include file) produces output: uc = 255 sc = -1 us = 65535 ss = -1 ui = 4294967295 si = -1 ul = 18446744073709551615 sl = -1 ull = 18446744073709551615 sll = -1 c = 'q' f = 1.230000 d = 3.141593 ld = 6.283185 yes = true no = false u16 = 65535 s16 = -1 uge32 = 4294967295 sge32 = -1 runtime = 365 now = 1770371790 offset = 27 uf32 = 18446744073709551615 sf32 = -1 c * now / 1e8 * ld = 12569.638642 foo = "foo" bas = (const char *) "bas"