Re: 64bit format strings



On Tue, 18 Jan 2005, Stefan Westerfeld wrote:

  Hi!

On AMD64, I currently get quite some warnings when compiling BEAST code
that contains a printf (or g_print, g_strdup_printf or similar) which
prints a 64 bit integer. The reason is that the format specifier that
indicates that a guint64 value is to be printed is different on AMD64.
On AMD64 with gcc, glib-2.0 defines g(u)int64 as long values (not long
long values), thus the format specifier for printf should be "%ld" not
"%lld".

Thus, for instance in the glib-2.0 source, there is:

#define FORMAT64 "%" G_GINT64_FORMAT " %" G_GUINT64_FORMAT "\n"
 string = g_strdup_printf (FORMAT64, gi64t1, gu64t1);
 sscanf (string, FORMAT64, &gi64t2, &gu64t2);
 g_free (string);
 g_assert (gi64t1 == gi64t2);
 g_assert (gu64t1 == gu64t2);

in tests/type-test.c.

Is it okay to start committing fixes to the BEAST CVS for this, which
would for instance fix the following compiler warnings:

g++ -DG_LOG_DOMAIN=\"SFI\" -DG_DISABLE_CONST_RETURNS -I/home/stefan/src/beast -I.. -pthread -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include  -g -DG_ENABLE_DEBUG -Wdeprecated -Wall -Wno-cast-qual -pipe -O2 -ftracer -finline-functions
-fno-keep-static-consts -fmessage-length=156 -c /home/stefan/src/beast/sfi/sfidl-parser.cc
/home/stefan/src/beast/sfi/sfidl-parser.cc: In member function `GTokenType Sfidl::Parser::parseStringOrConst(std::string&)':
/home/stefan/src/beast/sfi/sfidl-parser.cc:987: warning: long long int format, gint64 arg (arg 2)

no. while i'm currently not able to tell you what else to do to get
rid of these warnings, i believe G_GINT64_FORMAT to not be the solution.

for one, scattering format strings with G_GINT64_FORMAT makes the code
utterly unreadable, and for another, it doesn't properly cooperate with
i18n of strings either. (you don't translate "foo error: %lld < 0" twice
into all languages, once for %lld and once for %ld).

platform changes should not require format strings to change, if that
is the case, it's a bug and needs to be fixed (prolly somewhere in glibc/gcc).


  Cu... Stefan

---
ciaoTJ



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