bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AC_TYPE_LONG_LONG_INT and AC_TYPE_UNSIGNED_LONG_LONG_INT


From: Bruno Haible
Subject: Re: AC_TYPE_LONG_LONG_INT and AC_TYPE_UNSIGNED_LONG_LONG_INT
Date: Mon, 22 Oct 2007 13:04:14 +0200
User-agent: KMail/1.5.4

Paul Eggert wrote:
> On your host, 64-bit signed preprocessor numbers work,
> but the unsigned ones don't.

Yes, it looks like this, assuming that the autoconf tests are correct.

> Can you please try this code:
> 
> #if ! (18446744073709551615ULL <= -1u)
>   error in preprocessor;
> #endif
> 
> and tell me what diagnostics (if any) your compiler generates?
> 
> Perhaps the simplest workaround is to change the above test to something like 
> this:
> 
> #if ! (18446744073709551614ULL <= 18446744073709551615ULL)
>   error in preprocessor;
> #endif

Indeed, the result depends on the precise condition:

$ cat > foo.c
#if ! (18446744073709551615ULL <= -1u)
  error in preprocessor;
#endif
$ cc -Ae -O -c foo.c
cc: "foo.c", line 2: error 1000: Unexpected symbol: "in".
cc: "foo.c", line 2: warning 557: Missing declaration specifiers, "int" assumed.

$ cat > foo.c
#if ! (18446744073709551615ULL <= -1ull)
  error in preprocessor;
#endif
$ cc -Ae -O -c foo.c
cc: "foo.c", line 1: warning 501: Empty source file.

$ cat > foo.c
#if ! (-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
  error in preprocessor;
#endif
$ cc -Ae -O -c foo.c
cc: "foo.c", line 1: warning 501: Empty source file.

$ cat > foo.c
#if ! (18446744073709551614ULL <= 18446744073709551615ULL)
  error in preprocessor;
#endif
$ cc -Ae -O -c foo.c
cc: "foo.c", line 1: warning 501: Empty source file.

$ cat > foo.c
#if ! (18446744073709551615ULL <= 18446744073709551615ULL)
  error in preprocessor;
#endif
$ cc -Ae -O -c foo.c
cc: "foo.c", line 1: warning 501: Empty source file.

As you can see, all tests pass except the one that uses -1u. Whereas the
one with -1ull works.

Quite explainable:
  18446744073709551615ULL is 0xFFFFFFFFFFFFFFFFULL
  -1u                     is         0xFFFFFFFFU
so you end up comparing
  0xFFFFFFFFFFFFFFFFULL against 0x00000000FFFFFFFFULL
therefore I find it quite natural that this test fails.

I propose this fix (in gnulib, similarly for autoconf):


2007-10-22  Bruno Haible  <address@hidden>

        * m4/ulonglong.m4 (AC_TYPE_UNSIGNED_LONG_LONG_INT): Use -1ull, not
        -1u, in preprocessor expression.

--- m4/ulonglong.m4.orig        2007-10-22 13:00:48.000000000 +0200
+++ m4/ulonglong.m4     2007-10-22 13:00:16.000000000 +0200
@@ -1,4 +1,4 @@
-# ulonglong.m4 serial 7
+# 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,
@@ -21,7 +21,7 @@
     [ac_cv_type_unsigned_long_long_int],
     [AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
-         [[#if ! (18446744073709551615ULL <= -1u)
+         [[#if ! (18446744073709551615ULL <= -1ull)
              error in preprocessor;
            #endif
            unsigned long long int ull = 18446744073709551615ULL;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]