(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.

From Bruno Haible: 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 <waynec@spinnaker.com>.
This commit is contained in:
Paul Eggert 2001-09-17 21:49:30 +00:00
parent 34afb35e65
commit 1cae5f39c9

View File

@ -204,15 +204,27 @@ _array_ @<:@0@:>@ = 0
# AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
# -----------------------------------------
# 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.
m4_define([AC_LANG_INT_SAVE(C)],
[AC_LANG_PROGRAM([m4_default([$1], [@%:@include <stdio.h>])],
[FILE *f = fopen ("conftest.val", "w");
if (!f)
[AC_LANG_PROGRAM([$1
unsigned long conftestval () { return $2; }
@%:@include <stdio.h>
@%:@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);])])
])])
# ----------------- #