This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] {,U}LLONG_{MIN,MAX} with -D_GNU_SOURCE (BZ #1228)


Hi!

If /usr/lib/gcc/*/*/include/ comes first in the search path
(the default case), LLONG_MAX etc. aren't defined for -D_GNU_SOURCE
or -D_ISOC99_SOURCE unless -std=c99 is used.  The GCC header
only checks for __STDC_VERSION__ >= 199901L.
If just -D_ISOC99_SOURCE and not -std=c99, then LLONG_MAX etc.
is not defined properly for any inclusion order, as LONG_LONG_MAX etc.
aren't defined in that case (GCC limits.h protects them
with defined __USE_GNU).

The following patch should cure this.
But I'm not sure if _ISOC99_SOURCE shouldn't be ammended with __USE_XOPEN2K
or something similar, as POSIX2K requires LLONG_MAX etc. in limits.h,
so a pure -D_XOPEN_SOURCE=600 (without -std=c99) or
-D_POSIX_C_SOURCE=200112L wouldn't bring those macros into the namespace. 

I have checked GCC limits.h back to 2.96 ages and __LONG_LONG_MAX__ was
always defined.

2005-09-13  Jakub Jelinek  <jakub@redhat.com>

	[BZ #1228]
	* include/limits.h (LLONG_MIN, LLONG_MAX, ULLONG_MAX): Make sure these
	are defined for -D_GNU_SOURCE or -D_ISOC99_SOURCE even when not
	-std=c99.

--- libc/include/limits.h	2005-08-15 15:37:07.000000000 +0200
+++ libc/include/limits.h	2005-09-13 17:39:27.000000000 +0200
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991, 92, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1996, 1997, 1998, 1999, 2000, 2005
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -122,20 +123,20 @@
 #if defined __GNUC__ && !defined _GCC_LIMITS_H_
 /* `_GCC_LIMITS_H_' is what GCC's file defines.  */
 # include_next <limits.h>
+#endif
 
 /* The <limits.h> files in some gcc versions don't define LLONG_MIN,
    LLONG_MAX, and ULLONG_MAX.  Instead only the values gcc defined for
    ages are available.  */
-# ifdef __USE_ISOC99
-#  ifndef LLONG_MIN
-#   define LLONG_MIN	LONG_LONG_MIN
-#  endif
-#  ifndef LLONG_MAX
-#   define LLONG_MAX	LONG_LONG_MAX
-#  endif
-#  ifndef ULLONG_MAX
-#   define ULLONG_MAX	ULONG_LONG_MAX
-#  endif
+#if defined __USE_ISOC99 && defined __GNUC__
+# ifndef LLONG_MIN
+#  define LLONG_MIN	(-LLONG_MAX-1)
+# endif
+# ifndef LLONG_MAX
+#  define LLONG_MAX	__LONG_LONG_MAX__
+# endif
+# ifndef ULLONG_MAX
+#  define ULLONG_MAX	(LLONG_MAX * 2ULL + 1)
 # endif
 #endif
 


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]