In message <[EMAIL PROTECTED]>, Tom Tromey writes:
>Your patch has a problem if sizeof(int)==sizeof(char).
Oops, missed that one. Another case we'll rarely if ever meet, but
permitted by ANSI.
This defect is easy enough to correct by making use of your idea of a
potentially negative array dimension - we can try compiling "int
a[(char)-1];" which will compile if char is unsigned, and fail if it's
signed. Revised patch attached.
BTW if these are applied, then Kaveh Ghazi's AC_COMPILE_CHECK_SIZEOF
probably ought to replace AC_CHECK_SIZEOF. This uses the switch trick
to find the size of a type with one or more uses of AC_TRY_COMPILE. So
it doesn't necessarily win by being faster (but it does check more
likely sizes first which will help), but it will work when
cross-compiling.
One minor issue is that it checks for sizes of 1, 2, 4, 8, and 16 by
default (you can supply other sizes to check for). But this means it
isn't a complete drop-in replacement. Perhaps a binary chop approach
could be used to allow it to find the size of any type in a sensible
number of attempts. It would be a little cumbersome as you can only
get yes or no from AC_TRY_COMPILE - "<" versus ">=" (or "<=" vs ">").
It would be better if you could determine "<", "==", or ">" in one
try.
Cheers,
Olly
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(, [int a[(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