Jump to: navigation, search

I'm sorry Netocrat, but according to the standard I'm allowed to search for the terminating null-character using strchr(). You have just made that impossible. --Jannis 08:25, 14 March 2006 (GMT)

Ack, the fix should have been only the addition of the post-increment operator. I recently added a style guideline that functions should have a single exit-point, and tried to convert the code to match. In this case though, I think that following that guideline would actually lessen the readability of the code by making it a lot less concise, so I don't think it should apply. I'll update the guideline to reflect that. Since you're starting to contribute code, you may want to comment on / add to the style guidelines being developed for the wiki. --Netocrat 14:34, 14 March 2006 (GMT)

...although "impossible" is an overstatement. Six characters can be added to the code I posted to deal with searching for null-characters:

char *strchr(const char *s, int c)
{
    while (*s != (char)c)
        if (!*s)
            break;
        else s++;
    return *s || !c ? (char *)s : 0;
}

An argument could be mounted by a zealous single-exit advocate that this is preferable to the version you posted. There are pros and cons to both though: Style#Multiple_Exit_Points. --Netocrat 14:54, 14 March 2006 (GMT)

Well, the "impossible" was pointing at the functions behaviour, disregarding any possibility to bend things like you demonstrated. I think it serves to illustrate the point that blanket bans are a bad thing. --Jannis 17:48, 14 March 2006 (GMT)

Personal tools