GNOME Bugzilla – Bug 108699
missing suffixes from 64-bit constant defines
Last modified: 2004-12-22 21:47:04 UTC
Compiling glib 2.2.1 under HP-UX 11.11 with the HP ANSI C compiler yields warning messages such as cc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -DG_LOG_DOMAIN=\"GLib\" -DG_DISABLE_CAST_CHECKS -DG_DISABLE_DEPRECATED -DGLIB_COMPILATION -D_REENTRANT -L/usr/local/lib -c gstrfuncs.c +Z -DPIC -o gstrfuncs.lo^M cc: "gstrfuncs.c", line 675: warning 602: Integer constant exceeds its storage. ^M cc: "gstrfuncs.c", line 676: warning 602: Integer constant exceeds its storage. ^M cc: "gstrfuncs.c", line 713: warning 602: Integer constant exceeds its storage. ^M (there is one other file where this happens as well). Extracting bits and pieces into a test file: #include <stdio.h> typedef unsigned int guint; #define G_MAXUINT64 ((guint64) 0xffffffffffffffff) main() { guint64 cutoff; guint64 cutlimb; guint base; printf("sizeof guint64 %d\n",sizeof(unsigned long long)); cutoff = G_MAXUINT64 / base; cutoff = G_MAXUINT64 % base; } shows the same warnings. The warnings go away if the G_MAXUINT64 define is changed to: #define G_MAXUINT64 ((guint64) 0xffffffffffffffffULL) The cast as guint64 is insufficient to convince the compiler that this is supposed to be an unsigned 64-bit constant. It would seem this affects three defines in glibconfig.h: #define G_MININT64 ((gint64) 0x8000000000000000LL) #define G_MAXINT64 ((gint64) 0x7fffffffffffffffLL) #define G_MAXUINT64 ((guint64) 0xffffffffffffffffULL) which may need to become: #define G_MININT64 ((gint64) 0x8000000000000000LL) #define G_MAXINT64 ((gint64) 0x7fffffffffffffffLL) #define G_MAXUINT64 ((guint64) 0xffffffffffffffffULL) At least that eliminated the compiler warnings with the HP-UX ANSI C compiler.
there was a typo in the initial report where it showed the defines as already having "LL" and "ULL."
G_GINT64_CONSTANT() should be used for portability (L vs. LL)
This bug is "urgent" with AIX compiler (xlc) because value given to variable with G_MAXINT64 is 0xFFFFFFFF and not 0x7FFFFFFFFFFFFFFF. Try this: file longlong.c: ------------------------------------------- #include <stdio.h> long long badmax = 0x7fffffffffffffff; long long max = 0x7fffffffffffffffLL; int main(int argc, char**argv) { printf("%d %llx\n", sizeof(badmax), badmax); printf("%d %llx\n", sizeof(max), max); } ------------------------------------------- $ cc longlong.c -o longlong "ll.c", line 3.20: 1506-207 (W) Integer constant 0x7fffffffffffffff out of range. $ ./longlong 8 ffffffff 8 7fffffffffffffff ------------------------------------------- According to your comment, I think the good correction is : #define G_MININT64 ((gint64) G_GINT64_CONSTANT(0x8000000000000000)) #define G_MAXINT64 ((gint64) G_GINT64_CONSTANT(0x7fffffffffffffff)) #define G_MAXUINT64 ((guint64) G_GINT64_CONSTANT(0xffffffffffffffffU)) -------------------------------------------- with this modification, I have the following result: #include <stdio.h> #include <glibconfig.h> long long max = G_MAXINT64; int main(int argc, char**argv) { printf("%d %llx\n", sizeof(max), max); } $ ./longlong 8 7fffffffffffffff
Fixed in HEAD and glib-2-2 branch. Tue May 20 14:17:20 2003 Manish Singh <yosh@gimp.org> * configure.in: wrap 64-bit MIN/MAX limit constants in G_GINT64_CONSTANT. Fixes bug #108699.
*** Bug 113991 has been marked as a duplicate of this bug. ***