Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: C++ features for C Date: Thu, 17 May 2018 14:07:49 -0700 Organization: None to speak of Lines: 46 Message-ID: References: <11edbfd7-461d-4579-8ac7-a9e84a6b7630@googlegroups.com> <726d9572-f3c9-4f44-846d-eb49d6750d64@googlegroups.com> <2vjLC.94102$JJ3.94015@fx23.iad> <437a888c-00fc-4c72-a009-8ee019f6b76c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: h2725194.stratoserver.net; posting-host="6dd19cd3091e1460a04414b367a948c0"; logging-data="5580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+a9TYrcKSvuyVwZCaP1/St" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qm0OqcK6NdTx31tZLOcT53I9r+A= sha1:CBJyItH8f5eOJAMCj7RfwaQ0IC4= Xref: csiph.com comp.lang.c:130734 supercat@casperkitty.com writes: > On Thursday, May 17, 2018 at 1:04:55 PM UTC-5, Scott Lurndal wrote: >> Why would you not use >> >> printf(PRIu32, x); >> >> ? >> >> Likesize, for uint64_t x=6; >> >> printf("The value is " PRIu64 "\n", x); >> ? > > I find something like "(%08X,%08X)" more readable than something like > "(08" PRIX32 ",08" PRIX32 ")". Perhaps you don't. > > How common are platforms where "%ld" couldn't be a usable specifier for > a 32-bit integer? Most of the platforms I've seen where "long" is greater > than 32 bits seem to promote all variadic integer arguments to that type, > and would thus be able to support use of "%ld" for a 32-bit int. No platforms promote integer arguments to that *type*. They might extend them to that *size*. Using "%ld" with an int argument produces the "correct" results on the the systems I have access to at the moment. But using correct format strings is a far better use of my time than figuring out, based on the behavior of the compilers and target systems I happen to be concerned with today, how I can subvert the rules and get away with it (and deciding I can ignore the warnings that gcc and clang both give by default). I don't often use the formats defined in , mostly because I find them difficult to remember (of course that's self-reinforcing). Instead I generally convert to a predefined type than I know to be wide enough. int32_t x = 10; int64_t y = 20; printf("x = %ld, y = %lld\n", (long)x, (long long)y); -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"