Hi folks,
I noticed that it's possible to change AC_C_CHAR_UNSIGNED and
AC_C_LONG_DOUBLE to use AC_TRY_COMPILE rather than AC_TRY_RUN by using
the "switch with duplicate case labels" trick.
Benefits:
* Works equally well when cross-compiling
* Faster - no linking, and no test program to run
Only one potential down side I can see - is it known that this trick
works as expected everywhere?
If this patch doesn't get applied, note that it corrects an obscure
problem with the existing AC_C_CHAR_UNSIGNED: this won't work as
intended on platforms where CHAR_BIT >= 9 bits (very uncommon these
days, but allowed by ANSI IIRC). There it will always report that
char is unsigned since 255 will be a valid value for a signed char.
Cheers,
Olly
===
Suggested ChangeLog entry:
* acspecific.m4(AC_C_CHAR_UNSIGNED, AC_C_LONG_DOUBLE): Use
AC_TRY_COMPILE and duplicate case labels trick instead of
AC_TRY_RUN.
===
diff -u -r1.222 acspecific.m4
--- acspecific.m4 2000/02/10 13:14:58 1.222
+++ acspecific.m4 2000/02/19 11:39:36
@@ -2395,17 +2395,8 @@
#endif
], ac_cv_c_char_unsigned=yes, ac_cv_c_char_unsigned=no)
else
-AC_TRY_RUN(
-[/* volatile prevents gcc2 from optimizing the test away on sparcs. */
-#if !defined(__STDC__) || __STDC__ != 1
-# define volatile
-#endif
-int
-main()
-{
- volatile char c = 255;
- exit(c < 0);
-}], ac_cv_c_char_unsigned=yes, ac_cv_c_char_unsigned=no)
+AC_TRY_COMPILE(, [switch (0) case -1: case (char)-1:;],
+ ac_cv_c_char_unsigned=yes, ac_cv_c_char_unsigned=no)
fi])
if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
AC_DEFINE(__CHAR_UNSIGNED__)
@@ -2420,16 +2411,13 @@
[if test "$GCC" = yes; then
ac_cv_c_long_double=yes
else
-AC_TRY_RUN(
-[int
-main()
-{
- /* The Stardent Vistra knows sizeof(long double), but does not
+AC_TRY_COMPILE(,
+[/* The Stardent Vistra knows sizeof(long double), but does not
support it. */
long double foo = 0.0;
/* On Ultrix 4.3 cc, long double is 4 and double is 8. */
- exit(sizeof(long double) < sizeof(double));
-}],
+ switch (0) case sizeof(long double)<sizeof(double): case 1:;
+],
ac_cv_c_long_double=yes, ac_cv_c_long_double=no)
fi])
if test $ac_cv_c_long_double = yes; then