5 ms·
I find this style of formatting specifiers an eyesore: fprintf (stderr, _("%"PRIuMAX"+%"PRIuMAX" records in\n" "%"PRIuMAX"+%"PRIu
by Luyt 11y ago
I find this style of formatting specifiers an eyesore:
fprintf (stderr,
_("%"PRIuMAX"+%"PRIuMAX" records in\n"
"%"PRIuMAX"+%"PRIuMAX" records out\n"),
r_full, r_partial, w_full, w_partial);
- LukeShu 11y agoI assume you mean the `%"PRIuMAX"` bits. It is an eyesore, but it is how to portably write the specifiers for types whose size my vary across architectures. That is, blame POSIX, not GNU coding style.
- _kst_ 11y agoThe `PRIuMAX` et al macros are specified by ISO C (starting with the 1999 standard), not (just) by POSIX.
- LukeShu 11y agoThat makes sense; the most recent editions of POSIX "import" ISO C '99. I had a copy of POSIX handy to check it, but not ISO C :)
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- __david__ 11y agoYeah, it's ugly, but it's sadly the only way to correctly do cross platform prints where the type may or may not be 64 bit.
- _kst_ 11y agoThe `PRIuMAX` macro in particular is not necessary. It expands to a format usable for `uintmax_t`, but you can also use `"%ju"`. Both were introduced in ISO C99. (Unless your `printf` implementation doesn't recognize `"%ju"`, and the `PRIuMAX` macro and friends are defined in some non-standard system-specific manner.)
- e12e 11y agoRelated, the recently posted "How to write C in 2016": https://news.ycombinator.com/item?id=10864176 https://news.ycombinator.com/item?id=10864176
- garethrees 11y agoHow is this supposed to work? The underscore is a convenience macro for the gettext localization function. But gettext works by looking up its string argument in the localization database, and here the string varies from one platform to another, so how can you be sure that the localization will be found? I guess the answer is that you have to redo the localization for each platform that has a different expansion of PRIuMAX. But that's horrible: the localization will be identical except for the format specifiers, which will just be copied from the English version of the string. Is there support for automating this in the translation toolchain?
- arantius 11y agoWhat is the behavior of gettext() if the message is not found? (This question is the answer to your question.)
- garethrees 11y agoIf the message is not found, gettext returns the argument unchanged, which would be a bug (English text incorrectly appearing instead of localized text). So that's not it. The answer to my question is that xgettext and gettext have special handling for PRIuMAX and the other formatting macros in inttypes.h. http://www.gnu.org/software/gettext/manual/gettext.html#Preparing-Strings http://www.gnu.org/software/gettext/manual/gettext.html#Prep...