At 06:33 PM 05/23/2001, Greg Stein wrote:
And we *should* use strchr(). Unwrapping that into a loop is bogus. Even if
the compiler doesn't optimize it, the C library has highly optimized
versions which isn't going to happen with our own implementation.

Since I was curious, I went looking for one:

char * strchr (
        const char * string,
        int ch
        )
{
        while (*string && *string != (char)ch)
                string++;

        if (*string == (char)ch)
                return((char *)string);
        return(NULL);
}

Well, it's somewhat optimized, but not quite how I would have written it, and it's horribly formatted.

char * strchr(const char *string, int ch)
    {
    while(*string && (*string != (char)ch))
        string++;

    return(*string ? (char *)string : NULL);
    }

Ah, much better.

--
Greg Marr
[EMAIL PROTECTED]
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"



Reply via email to