1 Oct 2005 01:05
Re: printf (_("...%zu..."), X) where X is of type size_t
Eric Blake <ericblake <at> comcast.net>
2005-09-30 23:05:52 GMT
2005-09-30 23:05:52 GMT
> >> > +/* Determine a printf conversion specifier that is appropriate for size_t.
> >> > + Ideally, we'd just use the c99-specified `z' length modifier, defining
> >> > + PRI_z to "zu", but that's not portable. */
> >> ...
> >> I thought about doing that a while ago but gave it up because it
> >> appears that this sort of approach will run afoul of gettext.
> > ...
> > Maybe it's time that we provide a gnulib module for printf
>
> Personally I'd rather not head down that path. printf is the biggest
> cesspool in the C library, and lots of things that C likes to sweep
> under the rug finds its way into printf somehow: floating-point
> accuracy, cancellation points, multibyte encoding errors, signal
> handling, storage allocation, wrong-sized types for the job, etc.,
> etc. I suppose we could drag glibc's printf into gnulib, but I
> wouldn't envy the task of doing that, or maintaining the result.
When I wrote my suggestion, I was thinking more along the
lines of a thin wrapper, whose sole job in life is to translate the
format string into something that the system's vprintf can already
handle, without ever unwrapping the va_args itself. For that
matter, since the translation does not need to know what the
va_args are, maybe my suggestion is better written like this:
printf (printf_format (_("The size is %zu.")), size);
where we only provide printf_format, and its job is
to turn the "%z" into "%l" or "%ll" in the translation,
as appropriate.
(Continue reading)
.
RSS Feed