Paul Eggert wrote: > Bruno Haible <[EMAIL PROTECTED]> writes: > > > #if ! (-2147483648LL < 0) > > ... > > #if ! (-9223372036854775807LL < 0) > > If a compiler can't handle that sort of line, then its bugs are more > serious, since it's relatively common to do preprocessor checks > like "#if LLONG_MIN < LONG_MIN".
OK. Actually the Sun C compiler does not have this bug when generating 64-bit code, i.e. when the option -xarch=v9 is used. So the bug affects only 32-bit builds, which IMO is acceptable. > How about this idea instead? We sort-of-combine the tests for > unsigned long long and for signed long long, so that they always > return consistent answers. The combined test will be the union of the > current tests. Yes, I like the idea. > One can AC_REQUIRE the other, for example, and use its answer. But I shudder at the idea of mutual AC_REQUIREs. How about of simply merging the tests, like this? (Untested.) This is just a proposal; of course the patch should first go into autoconf. Btw, isn't that a typo in longlong.m4? | (ll < i) | (ll > i) See ulonglong.m4: | ull << i | ull >> i Is that to test the availability of the runtime routines for shifting or for comparison? Comparisons will always be inlined by the compiler, no? 2007-10-24 Bruno Haible <[EMAIL PROTECTED]> * m4/longlong.m4 (_AC_TYPE_LONG_LONG_SNIPPET): New macro, extracted from AC_TYPE_LONG_LONG_INT and AC_TYPE_UNSIGNED_LONG_LONG_INT. (AC_TYPE_LONG_LONG_INT): Use it. * m4/ulonglong.m4 (AC_TYPE_UNSIGNED_LONG_LONG_INT): Likewise. * modules/strtoull (Files): Add m4/longlong.m4. * modules/strtoumax (Files): Likewise. *** m4/longlong.m4.orig 2007-10-24 13:17:26.000000000 +0200 --- m4/longlong.m4 2007-10-24 13:16:24.000000000 +0200 *************** *** 1,4 **** ! # longlong.m4 serial 11 dnl Copyright (C) 1999-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, --- 1,4 ---- ! # longlong.m4 serial 12 dnl Copyright (C) 1999-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, *************** *** 18,36 **** [ AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], [AC_LINK_IFELSE( ! [AC_LANG_PROGRAM( ! [[#if ! (-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) ! error in preprocessor; ! #endif ! long long int ll = 9223372036854775807ll; ! long long int nll = -9223372036854775807LL; ! typedef int a[((-9223372036854775807LL < 0 ! && 0 < 9223372036854775807ll) ! ? 1 : -1)]; ! int i = 63;]], ! [[long long int llmax = 9223372036854775807ll; ! return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) ! | (llmax / ll) | (llmax % ll));]])], [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. dnl If cross compiling, assume the bug isn't important, since dnl nobody cross compiles for this platform as far as we know. --- 18,24 ---- [ AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], [AC_LINK_IFELSE( ! [_AC_TYPE_LONG_LONG_SNIPPET], [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. dnl If cross compiling, assume the bug isn't important, since dnl nobody cross compiles for this platform as far as we know. *************** *** 63,68 **** --- 51,90 ---- fi ]) + # Expands to a C program that can be used to test for simultaneous support + # of 'long long' and 'unsigned long long'. We don't want to say that + # 'long long' is available if 'unsigned long long' is not, or vice versa, + # because too many programs rely on the symmetry between signed and unsigned + # integer types (excluding 'bool'). + AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET], + [ + AC_LANG_PROGRAM( + [[/* Test preprocessor. */ + #if ! (-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) + error in preprocessor; + #endif + #if ! (18446744073709551615ULL <= -1ull) + error in preprocessor; + #endif + /* Test literals. */ + long long int ll = 9223372036854775807ll; + long long int nll = -9223372036854775807LL; + unsigned long long int ull = 18446744073709551615ULL; + /* Test constant expressions. */ + typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) + ? 1 : -1)]; + typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 + ? 1 : -1)]; + int i = 63;]], + [[/* Test availability of runtime routines for shift and division. */ + long long int llmax = 9223372036854775807ll; + unsigned long long int ullmax = 18446744073709551615ull; + return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) + | (llmax / ll) | (llmax % ll) + | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) + | (ullmax / ull) | (ullmax % ull));]]) + ]) + # This macro is obsolescent and should go away soon. AC_DEFUN([gl_AC_TYPE_LONG_LONG], [ *** m4/ulonglong.m4.orig 2007-10-24 13:17:26.000000000 +0200 --- m4/ulonglong.m4 2007-10-24 13:16:25.000000000 +0200 *************** *** 1,4 **** ! # ulonglong.m4 serial 8 dnl Copyright (C) 1999-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, --- 1,4 ---- ! # ulonglong.m4 serial 9 dnl Copyright (C) 1999-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, *************** *** 20,36 **** AC_CACHE_CHECK([for unsigned long long int], [ac_cv_type_unsigned_long_long_int], [AC_LINK_IFELSE( ! [AC_LANG_PROGRAM( ! [[#if ! (18446744073709551615ULL <= -1ull) ! error in preprocessor; ! #endif ! unsigned long long int ull = 18446744073709551615ULL; ! typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1 ! ? 1 : -1)]; ! int i = 63;]], ! [[unsigned long long int ullmax = 18446744073709551615ull; ! return (ull << 63 | ull >> 63 | ull << i | ull >> i ! | ullmax / ull | ullmax % ull);]])], [ac_cv_type_unsigned_long_long_int=yes], [ac_cv_type_unsigned_long_long_int=no])]) if test $ac_cv_type_unsigned_long_long_int = yes; then --- 20,26 ---- AC_CACHE_CHECK([for unsigned long long int], [ac_cv_type_unsigned_long_long_int], [AC_LINK_IFELSE( ! [_AC_TYPE_LONG_LONG_SNIPPET], [ac_cv_type_unsigned_long_long_int=yes], [ac_cv_type_unsigned_long_long_int=no])]) if test $ac_cv_type_unsigned_long_long_int = yes; then *** modules/strtoull.orig 2007-10-24 13:17:26.000000000 +0200 --- modules/strtoull 2007-10-24 13:07:18.000000000 +0200 *************** *** 4,9 **** --- 4,10 ---- Files: lib/strtoull.c m4/ulonglong.m4 + m4/longlong.m4 m4/strtoull.m4 Depends-on: *** modules/strtoumax.orig 2007-10-24 13:17:26.000000000 +0200 --- modules/strtoumax 2007-10-24 13:07:32.000000000 +0200 *************** *** 4,9 **** --- 4,10 ---- Files: lib/strtoumax.c m4/ulonglong.m4 + m4/longlong.m4 m4/strtoumax.m4 Depends-on: