64bit format strings
- From: Stefan Westerfeld <stefan space twc de>
- To: beast gnome org
- Subject: 64bit format strings
- Date: Tue, 18 Jan 2005 19:04:40 +0100
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)
/home/stefan/src/beast/sfi/sfidl-parser.cc: In member function `GTokenType Sfidl::Parser::parseParamHints(Sfidl::Param&)':
/home/stefan/src/beast/sfi/sfidl-parser.cc:1528: warning: long long unsigned int format, guint64 arg (arg 2)
/home/stefan/src/beast/sfi/sfidl-parser.cc:1550: warning: long long int format, gint64 arg (arg 2)
by the following changes:
Index: sfidl-parser.cc
===================================================================
RCS file: /cvs/gnome/beast/sfi/sfidl-parser.cc,v
retrieving revision 1.46
diff -u -r1.46 sfidl-parser.cc
--- sfidl-parser.cc 3 Dec 2004 20:38:39 -0000 1.46
+++ sfidl-parser.cc 18 Jan 2005 17:58:16 -0000
@@ -984,7 +984,7 @@
switch (ci->type)
{
case Constant::tInt:
- s = x = g_strdup_printf ("%lldLL", ci->i);
+ s = x = g_strdup_printf ("%" G_GINT64_FORMAT "LL", ci->i);
g_free (x);
break;
case Constant::tFloat:
@@ -1525,7 +1525,7 @@
token_as_string = g_strdup_printf ("\"%s\"", x);
g_free (x);
break;
- case G_TOKEN_INT: token_as_string = g_strdup_printf ("%llu", scanner->value.v_int64);
+ case G_TOKEN_INT: token_as_string = g_strdup_printf ("%" G_GUINT64_FORMAT, scanner->value.v_int64);
break;
case G_TOKEN_FLOAT: token_as_string = g_strdup_printf ("%.17g", scanner->value.v_float);
break;
@@ -1547,7 +1547,7 @@
else switch (ci->type)
{
case Constant::tInt:
- token_as_string = g_strdup_printf ("%lldLL", ci->i);
+ token_as_string = g_strdup_printf ("%" G_GINT64_FORMAT "LL", ci->i);
break;
case Constant::tFloat:
token_as_string = g_strdup_printf ("%.17g", ci->f);
(there are more of these changes necessary for quite some other files),
but after applying this patch, the warnings in sfidl-parser.cc go away.
The motivation for fixing the warnings is that it is hard to spot real
problems if your compile process is flooded with warnings anyway.
Cu... Stefan
--
Stefan Westerfeld, Hamburg/Germany, http://space.twc.de/~stefan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]