[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf (_("...%zu..."), X) where X is of type size_t

From: Ben Pfaff
Subject: Re: printf (_("...%zu..."), X) where X is of type size_t
Date: Fri, 30 Sep 2005 16:00:45 -0700
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Paul Eggert <address@hidden> writes:

> 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.

I have an idea, but I don't know whether it's reasonable.  How
about a function that does a makes a copy of a format string, in
the process doing a textual search-and-replace of %zu, etc. by
the local system's appropriate size modifier?  Then the above
would become something like:

        printf (fix_sizes (_("The size is %zu.\n")), size);

We'd want to write an Autoconf test for whether `z' and friends
are supported so that fix_sizes could be stubbed out if it was
unneeded, e.g.

        #ifdef HAS_C99_PRINTF
        #define fix_sizes(FORMAT) (FORMAT)

Presumably fix_sizes() would be written something like quote() to
avoid the need to explicitly free a dynamically allocated string.
Ben Pfaff 
email: address@hidden
web: http://benpfaff.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]