> > This is due to the gcc 2.7.2.1 preprocessor unable to calculate or > > compare long longs. > > Yes, your analysis is correct. Last year, Paul Eggert decided that > we had long enough supported compilers with pre-C99 preprocessors. > Yes, we want to use UINTMAX_MAX in preprocessor expressions. > > Nevertheless, in memchr2.c it would be possible to write an if (...) > instead of #if. This will cause warnings on compilers which don't have > 64-bit integers at all;
How so? The gnulib stdint.h replacement guarantees that UINTMAX_MAX is of the largest supportable type; if long long is not supported, then it is not a 64-bit integer. Unless you're claiming that the compiler might warn about the explicit shift by 32 bits on platforms where my patch below now compiles the shift (in a dead code branch) where it was previously omitted by the #if, but that's okay with me (ie. I don't see the point in making the code uglier with <<31<<1 just for a compiler that only supports 32-bit integers and warns on explicit shift by 32). > but it will allow compilation on compilers which > have 64-bit integers in the expressions but not in the preprocessor. > Eric, do you agree? Yes; I'm checking in the following (should we also change memchr.c to match, since I borrowed from there in writing memchr2.c)? >From 218c1d232b2568450b4581f93d544e4d3af59c36 Mon Sep 17 00:00:00 2001 From: Eric Blake <[EMAIL PROTECTED]> Date: Mon, 21 Apr 2008 09:57:07 -0600 Subject: [PATCH] Work around preprocessors that don't handle UINTMAX_MAX. * lib/memchr2.c (memchr2): Avoid embedded #if. Reported by Alain Guibert, fix suggested by Bruno Haible. Signed-off-by: Eric Blake <[EMAIL PROTECTED]> --- ChangeLog | 8 +++++++- lib/memchr2.c | 25 +++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9153749..9266f7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-04-21 Eric Blake <[EMAIL PROTECTED]> + + Work around preprocessors that don't handle UINTMAX_MAX. + * lib/memchr2.c (memchr2): Avoid embedded #if. + Reported by Alain Guibert, fix suggested by Bruno Haible. + 2008-04-21 Simon Josefsson <[EMAIL PROTECTED]> * doc/posix-functions/strftime.texi (strftime): Explain better diff --git a/lib/memchr2.c b/lib/memchr2.c index d5b0a78..3853343 100644 --- a/lib/memchr2.c +++ b/lib/memchr2.c @@ -83,18 +83,19 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n) charmask2 = c2 | (c2 << 8); charmask1 |= charmask1 << 16; charmask2 |= charmask2 << 16; -#if 0xffffffffU < UINTMAX_MAX - magic_bits |= magic_bits << 32; - charmask1 |= charmask1 << 32; - charmask2 |= charmask2 << 32; - if (8 < sizeof longword1) - for (i = 64; i < sizeof longword1 * 8; i *= 2) - { - magic_bits |= magic_bits << i; - charmask1 |= charmask1 << i; - charmask2 |= charmask2 << i; - } -#endif + if (0xffffffffU < UINTMAX_MAX) + { + magic_bits |= magic_bits << 32; + charmask1 |= charmask1 << 32; + charmask2 |= charmask2 << 32; + if (8 < sizeof longword1) + for (i = 64; i < sizeof longword1 * 8; i *= 2) + { + magic_bits |= magic_bits << i; + charmask1 |= charmask1 << i; + charmask2 |= charmask2 << i; + } + } magic_bits = (UINTMAX_MAX >> 1) & (magic_bits | 1); /* Instead of the traditional loop which tests each character, -- 1.5.5 -- View this message in context: http://www.nabble.com/fpurge.c-error-when-building-m4-1.4.11-tp16705250p16808234.html Sent from the Gnulib mailing list archive at Nabble.com.