After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 108699 - missing suffixes from 64-bit constant defines
missing suffixes from 64-bit constant defines
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.2.x
Other HP-UX
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 113991 (view as bug list)
Depends on:
Blocks: 113992
 
 
Reported: 2003-03-18 20:14 UTC by rick jones
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description rick jones 2003-03-18 20:14:27 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.
Comment 1 rick jones 2003-03-18 20:22:17 UTC
there was a typo in the initial report where it showed the defines as
already having "LL" and "ULL." 
Comment 2 Manish Singh 2003-03-18 20:25:57 UTC
G_GINT64_CONSTANT() should be used for portability (L vs. LL)
Comment 3 Laurent Vivier 2003-05-15 13:55:17 UTC
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
Comment 4 Manish Singh 2003-05-20 21:19:12 UTC
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.
Comment 5 Manish Singh 2003-05-29 20:31:15 UTC
*** Bug 113991 has been marked as a duplicate of this bug. ***