This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix libdecnumber bootstrap on Tru64 (part 2)
- From: Roger Sayle <roger at eyesopen dot com>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: Richard Earnshaw <rearnsha at arm dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Ben Elliston <bje at au1 dot ibm dot com>
- Date: Tue, 20 Dec 2005 11:01:05 -0700 (MST)
- Subject: Re: [PATCH] Fix libdecnumber bootstrap on Tru64 (part 2)
On 20 Dec 2005, Gabriel Dos Reis wrote:
> | Many thanks. Here's the cast to int solution that I committed:
>
> I think this solution is wrong.
Doh!
There's also a third possibility, an alternative implementation that
avoids the use of <ctype.h> functions completely, by observing that
this function has two calls, both of which test against a constant
reference string, one being a prefix of the other.
static Flag
decStrEqInf (const char *str)
{
if ((str[0] != 'I' && str[0] != 'i')
|| (str[1] != 'N' && str[1] != 'n')
|| (str[2] != 'F' && str[2] != 'f'))
return 0;
if (str[3] == '\0')
return 1;
return (str[3] == 'I' || str[3] == 'i')
&& (str[4] == 'N' || str[4] == 'n')
&& (str[5] == 'I' || str[5] == 'i')
&& (str[6] == 'T' || str[6] == 't')
&& (str[7] == 'Y' || str[7] == 'y')
&& str[8] == '\0';
}
Which has the benefit of being both faster and more portable?
Roger
--