[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
printf (_("...%zu..."), X) where X is of type size_t
From: |
Paul Eggert |
Subject: |
printf (_("...%zu..."), X) where X is of type size_t |
Date: |
Fri, 30 Sep 2005 15:45:56 -0700 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
address@hidden (Eric Blake) writes:
>> > +/* 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.
If 'size' is of type size_t, then where I was suggesting this:
unsigned long int s = size;
printf (_("The size is %lu.\n"), size);
the gettext manual suggests something like this instead:
char buf[INT_BUFSIZE_BOUND (size_t)];
sprintf (buf, "%" PRIuSIZE, size);
printf (_("The size is %s.\n"), buf1);
where we define PRIuSIZE in system.h. But this is even more awkward.
Perhaps GNU extensions PRIoSIZE, PRIuSIZE, PRIxSIZE, PRIXSIZE could be
added to GNU gettext. That would mean we could write this instead:
printf (_("The size is %"PRIuSIZE".\n"), size);
which would be nicer than either of the above.
It is curious that <inttypes.h> lacks the PRI* macros for size_t.
I wonder why they left them out?
- printf (_("...%zu..."), X) where X is of type size_t,
Paul Eggert <=