Re: 64bit format strings


On Fri, Jan 06, 2006 at 03:35:08PM -0500, Matthias Clasen wrote:
> On 1/6/06, Stefan Westerfeld <stefan space twc de> wrote:
> >
> > (1) Take no care that gint64 is defined by glib-2.0 as long long on
> > 32-bit platforms and as long on 64-bit platforms. This generates
> > compiler warnings on 64bit machines like Linux on AMD64.
> >
> > (2) Use glib's macros for formatting things. The code is less readable,
> > but works.
> >
> > (3) Use i18n, without using glib's macros: works, but generates the same
> > warnings on 64-bit platforms like Linux on AMD64 as (1).
> >
> > (4) Use i18n and glib's macros: breaks due to xgettext, which cannot
> > deal with preprocessor string concatenation. No internalization is
> > performed.
> >
> Does xgettext handle the PRI... macros which C99 has for the same purpose ?

Yes, I tried it now, and using PRId64 generates a message string like

#: gint64print.c:26
#, c-format
msgid "Progress: %<PRId64> bytes copied, %<PRId64> bytes to go\n"
msgstr ""

so that works. Both, xgettext and the gettext runtime perform quite some
special casing to implement this. And of course that will only work for
C99 code, but the code due to which I originally started the thread is

So the only remaining question is: does glib-2.x provide a guarantee
that gint64 (and similar types) work together with PRId64 (and similar
macros)? Then using PRId64 is a reasonable way to go.

Let me explain the last thing:

On a platform like Linux/AMD64 two integer types are 64bit integer
types, namely long and long long. These require two different format
strings, namely "%ld" and "%lld". Now a bad thing to do would be

  typedef long int int64_t; /* <- <stdint.h> */
  typedef long long gint64; /* <- glib-2.x */


  gint64 i;
  g_print ("i=" PRId64 "\n", i);

would break. But if glib guarantees that PRId64 will work for gint64 on
C99 systems, my problem is effectively solved.

   Cu... Stefan
Stefan Westerfeld, Hamburg/Germany,

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