[Top][All Lists]

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

Re: [Bruno Haible <address@hidden>] _AC_COMPUTE_INT forgets to include s

From: Paul Eggert
Subject: Re: [Bruno Haible <address@hidden>] _AC_COMPUTE_INT forgets to include stdio.h, stdlib.h
Date: Mon, 17 Sep 2001 15:01:02 -0700 (PDT)

> From: Akim Demaille <address@hidden>
> Date: 17 Sep 2001 11:04:18 +0200
> Fine!  Please, install.

OK, done.

> From: Bruno Haible <address@hidden>
> Date: Mon, 17 Sep 2001 15:07:08 +0200 (CEST)
> Actually, since you don't output the result with an 'L' suffix, the
> range of integers it handles is the same as the 'int' range.

We can't append 'L', since the constants are passed as args to 'expr',
and 'expr' needn't accept trailing 'L'.

But I don't think it's a problem, as C constants that do not fit in
'int' are of a wider type.  For example, with 32-bit int and 64-bit
long, 9223372036854775807 is of type 'long'.

This does bring up the good point that the macro doesn't work for
values greater than LONG_MAX and no greater than ULONG_MAX.  So I
installed the following combined patch which should address that
issue.  This macro does not allow negative numbers, but they're a
problem anyway (should they be parenthesized on output?  What about
LONG_MIN?)  and these issues can be deferred until later.  Right now
the macro is used only on nonnegative arguments.

2001-09-17  Paul Eggert  <address@hidden>

        * lib/autoconf/c.m4: (AC_LANG_INT_SAVE(C)):
        Allow expression to return any value that can fit into unsigned long
        (not int, as before).  Check for output errors.

2001-09-17  Bruno Haible <address@hidden>

        * lib/autoconf/c.m4: (AC_LANG_INT_SAVE(C)):
        Always include <stdio.h> and <stdlib.h>. Evaluate
        the expression in an extra function before these includes. Call
        fprintf "%d" only after ensuring the argument is of type 'int'.
        Reported by Wayne Chapeskie <address@hidden>.

Index: lib/autoconf/c.m4
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/c.m4,v
retrieving revision 1.153
diff -p -u -r1.153 c.m4
--- lib/autoconf/c.m4   2001/09/05 08:46:53     1.153
+++ lib/autoconf/c.m4   2001/09/17 21:46:05
@@ -204,15 +204,27 @@ _array_ @<:@0@:>@ = 0
 # -----------------------------------------
-# We need `stdio.h' to open a `FILE', so the prologue defaults to the
-# inclusion of `stdio.h'.
+# We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
+# But we include them only after the EXPRESSION has been evaluated.
-[AC_LANG_PROGRAM([m4_default([$1], address@hidden:@include <stdio.h>])],
-[FILE *f = fopen ("conftest.val", "w");
-if (!f)
+unsigned long conftestval () { return $2; }
address@hidden:@include <stdio.h>
address@hidden:@include <stdlib.h>],
+  FILE *f = fopen ("conftest.val", "w");
+  if (f)
+    {
+      unsigned long i = conftestval ();
+      if (0 <= ($2) && i == ($2))
+       {
+         fprintf (f, "%lu\n", i);
+         if (! ferror (f) && fclose (f) == 0)
+           exit (0);
+       }
+    }
   exit (1);
-fprintf (f, "%d", ($2));
-fclose (f);])])
 # ----------------- #

reply via email to

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