This is the mail archive of the libc-hacker@sources.redhat.com 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] |
Hi! This patch fixes two issues related to <limits.h>. The first issue (include/limits.h patch) is for non-gcc compilers on 64bit non-alpha (ie. sparc64, mips64, ppc64, ia64, whatever). The second fixes definition of WORD_BIT and LONG_BIT, because currently it is dependent on the order of included headers. Preprocessing following piece of code #define _GNU_SOURCE #include <limits.h> int bits [] = { WORD_BIT, LONG_BIT }; like gcc -E test.c gives 64, 64 on ia32, while gcc -I/usr/include -E test.c gives 32, 32. The issue is that in the former case, INT_MAX and LONG_MAX are defined after xopen_lim.h is included from the start of gcc's limits.h, so all macros are fine but those two, because there are INT_MAX/LONG_MAX used in #ifs. I've copied gcc logic of setting these defines up, so that things work both if glibc's limits.h are included first or gcc's limits.h come first and also for dual arch compilers which e.g. can set sizeof int using command line switches (they then define __INT_MAX__ during cpp0 invocations). 2000-10-20 Jakub Jelinek <jakub@redhat.com> * include/limits.h: Include bits/wordsize.h, use #if __WORDSIZE == 64 check instead of #ifdef __alpha__. * include/bits/xopen_lim.h (WORD_BIT, LONG_BIT): Don't count on INT_MAX, __INT_MAX__, LONG_MAX or __LONG_MAX__ being defined when this is included. --- libc/include/bits/xopen_lim.h.jj Tue Sep 26 09:22:42 2000 +++ libc/include/bits/xopen_lim.h Fri Oct 20 17:26:43 2000 @@ -92,23 +92,54 @@ /* Number of bits in a word of type `int'. */ -#if INT_MAX == 32767 -# define WORD_BIT 16 -#else -# if INT_MAX == 2147483647 -# define WORD_BIT 32 +#ifdef INT_MAX +# if INT_MAX == 32767 +# define WORD_BIT 16 +# else +# if INT_MAX == 2147483647 +# define WORD_BIT 32 +# else +/* Safe assumption. */ +# define WORD_BIT 64 +# endif +# endif +#elif defined __INT_MAX__ +# if __INT_MAX__ == 32767 +# define WORD_BIT 16 # else +# if __INT_MAX__ == 2147483647 +# define WORD_BIT 32 +# else /* Safe assumption. */ -# define WORD_BIT 64 +# define WORD_BIT 64 +# endif # endif +#else +# define WORD_BIT 32 #endif /* Number of bits in a word of type `long int'. */ -#if LONG_MAX == 2147483647 -# define LONG_BIT 32 -#else +#ifdef LONG_MAX +# if LONG_MAX == 2147483647 +# define LONG_BIT 32 +# else /* Safe assumption. */ -# define LONG_BIT 64 +# define LONG_BIT 64 +# endif +#elif defined __LONG_MAX__ +# if __LONG_MAX__ == 2147483647 +# define LONG_BIT 32 +# else +/* Safe assumption. */ +# define LONG_BIT 64 +# endif +#else +# include <bits/wordsize.h> +# if __WORDSIZE == 64 +# define LONG_BIT 64 +# else +# define LONG_BIT 32 +# endif #endif #endif /* bits/xopen_lim.h */ --- libc/include/limits.h.jj Tue Sep 26 09:22:42 2000 +++ libc/include/limits.h Fri Oct 20 16:48:45 2000 @@ -42,6 +42,8 @@ # ifndef _LIMITS_H # define _LIMITS_H 1 +#include <bits/wordsize.h> + /* We don't have #include_next. Define ANSI <limits.h> for standard 32-bit words. */ @@ -82,7 +84,7 @@ # define UINT_MAX 4294967295U /* Minimum and maximum values a `signed long int' can hold. */ -# ifdef __alpha__ +# if __WORDSIZE == 64 # define LONG_MAX 9223372036854775807L # else # define LONG_MAX 2147483647L @@ -90,7 +92,7 @@ # define LONG_MIN (-LONG_MAX - 1L) /* Maximum value an `unsigned long int' can hold. (Minimum is 0.) */ -# ifdef __alpha__ +# if __WORDSIZE == 64 # define ULONG_MAX 18446744073709551615UL # else # define ULONG_MAX 4294967295UL Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |