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: Wed, 04 Feb 2026 15:39:46 -0800 Organization: None to speak of Lines: 40 Message-ID: <878qd89iyl.fsf@example.invalid> 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 Injection-Date: Wed, 04 Feb 2026 23:39:47 +0000 (UTC) Injection-Info: dont-email.me; posting-host="adc50be3bbe0dba199a858e52ca7a4e7"; logging-data="2908820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nAqGpWdd4e+j0tkHCA1J5" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:BehM5AMk7cxEJ+iXzAaPoYyO6bE= sha1:78tA90bVP5Sgbrj9YJpJXyXuFGQ= Xref: csiph.com comp.lang.c:396598 Bart writes: [...] > 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 '?' Since you asked... '?' is 'f' (or 'g' or 'e', or 'a', or any of those in upper case). `x * y` is of type double. When an integer operand is multiplied by (or added to, or ...) a floating-point operand, the integer operand is converted to the type of the floating-point operand. The "usual arithmetic conversions" are moderately complicated, but that particular rule is simple enough that I didn't have to look it up (though I did double-check it, no pun intended). If I didn't know that, I'd look it up. If I wanted something other than the usual arithmetic conversions, I'd force the result I want using a cast or casts. And I know it's just an example, but in real life I'd spend some time thinking about *why* I'm multiplying a uintptr_t by a double (I can't think of a realistic scenario where that would be appropriate), and likely concluding that one or both of the operands should have been of some other type in the first place. Yes, printf requires an exact type for each argument. Yes, that can be inconvenient. But updating printf so it can take arguments of any type and know what to do with them would require changes to the language that nobody, as far as I know, has proposed. (Any such proposal that would work only for the *printf functions, not for arbitrary user-written code, would probably not be accepted.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */