MCENANEY WILLIAM J wrote:

> I'm back.  What's that I hear, a groan?  Grin.  Since "nice" is a vague word,
> I don't know what is nice about "!strcmp()."  But if we're talking about
> readability and aesthetic appeal, I would love to change C.  Call me a nit-
> picker.  But if I wanted to find out whether two strings were identical, I'd
> want to use an equal sign in my "if" statement.

Do you mean `=='? (an `=' is valid, but means something else). Using

        if (s1 == s2)

is perfectly valid, but means something completely different (i.e. 
Lisp's `eq', as opposed to `equal'). There are perfectly good reasons
for using either form; making `s1 == s2' stand for `strcmp(s1, s2) == 0'
would eliminate a useful option. It would also make C less consistent

        if ((char *)s1 == (char *)s2)

would mean something completely different to

        if ((int)s1 == (int)s2)

> Say I need to keep using strcmp().  Then I might define constants to stand
> for values that strcmp() returns.  I could write:
> 
>       if (strcmp(s1, s2) == SAME)
>           puts ("They're the same.");
>         else
>           puts ("They differ.");
> 
> I'm no expert in C, but I'm a perfectionist about readability.  Though my
> idea me not please an expert C programmer, it tells my readers what I mean.
> What do you think?

If you're that concerned about legibility, then it would probably be
better to define:

        int strings_equal(const char *s1, const char *s2)
        {
                return strcmp(s1, s2) == 0;
        }

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to