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:25:21 -0800 Organization: A noiseless patient Spider Lines: 63 Message-ID: <861piyi2y6.fsf@linuxsc.com> References: <10jfol6$2u6r8$1@news.xmission.com> <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> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 06 Feb 2026 10:25:25 +0000 (UTC) Injection-Info: dont-email.me; posting-host="0212364931b71f18d3f23c70ceb29fbc"; logging-data="79087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/04U/R2KfNecYJwqK7fvVMvHPtqPzYG8Q=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:/jN0/zBLd0+GoZp1Zt5shyy293g= sha1:5BCXRU03eYnKP6hSOS4//9ujdN8= Xref: csiph.com comp.lang.c:396617 Bart writes: > On 04/02/2026 14:22, Tim Rentsch wrote: > >> Bart writes: >> >>> On 03/02/2026 15:47, Tim Rentsch wrote: >> >> [...] >> >>>> If variable 'u' is declared as uint32_t, a way to print it that is >>>> easy and also type-safe is >>>> >>>> printf( " u is %lu\n", u+0LU ); >>> >>> What about a compound expression of several variables of mixed >>> integer types, possibly even mixed with floats, some of whose types >>> might either be conditional (depending on some macro), or opaque? >> >> What is an example of a conditional/macro-dependent type? > > Example from SDL2: > > #if defined(_MSC_VER) && (_MSC_VER < 1600) > ... > #ifndef _UINTPTR_T_DEFINED > #ifdef _WIN64 > typedef unsigned __int64 uintptr_t; > #else > typedef unsigned int uintptr_t; > ... > > Example from SQLITE3: > > #ifdef SQLITE_OMIT_FLOATING_POINT > # define double sqlite3_int64 > #endif > > >> Also what sort of opaque types do you have in mind? > > Things like time_t and clock_t, or the equivalent from libraries. > > Yes you could hunt down the exact underlying type (for clock_t in one > case, it was under 6 layers of typedefs and macros), but that would be > for a specific set of headers. > > For system headers, somebody could be using a header with different > definitions. For user-libraries, it might be a slightly different > version. > > >> What is the problem you want to solve here? > > The problem is that C expects an exact format-code when trying to use > *printf functions, and for that you need to know the exact types of > the expressions being passed. For example: > > uintptr_t x; // from above examples > double y; // > printf("x * y is %?", x * y); // What's '?' I understand. Thank you for the explanation.