Sujet : Re: a bit of history, Stealing a Great Idea from the 6600
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.archDate : 28. Jul 2024, 02:45:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v847r9$3kh8o$2@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Pan/0.159 (Vovchansk; )
On Sat, 4 May 2024 10:08:57 -0000 (UTC), Thomas Koenig wrote:
Just think of doing a unsigned loop with a lower bound that, due to some
error in the code or input, has an upper bound of 0-1...
Using the entire range of an unsigned integer type takes some care, but
can be done:
unsigned int i;
bool found;
...
/* length of s might be anything up to largest unsigned integer */
for (i = len(s);;)
{
if (i == 0)
{
found = false;
break;
} /*if*/
--i;
if (matches(s[i]))
{
found = true;
break
} /*if*/
} /*for*/
/* at this point, i will point to the matching element if found */