Pete Ryland wrote:

> > On Sat, 23 May 1998, Glynn Clements wrote:
> > 
> > >Personally, I avoid using `!strcmp(...)'; I find `strcmp(...) == 0' to
> > >be more intuitive.
> > 
> > __Personally__ I like the opposite ;-). I always use ! when I can.  It' s
> > faster and nicer. 
> 
> Don't be fooled!  Just because it looks smaller in your c source, it
> doesn't mean it'll be faster.  It *should* generate the same code, so the
> only reason to use one way over another is code readability.  IMHO, I
> think that Glynn's code is more readable, since it helps you realise that
> the condition will be true if the strings are equal.  Similarly for
> checking of error conditions or null pointers, I think that a compare with
> zero makes c code much more readable. (of course this is just my 2c which
> ain't worth much since the smallest unit of currency here is 5c :)

When checking for error (i.e. non-zero) returns from library
functions, I use `... != 0' (or `... == -1' if there are non-zero
return codes which don't indicate an error).

But for testing null pointers, I use `!'. In this context, it seems
reasonable (to me) to treat the value as a boolean, i.e. NULL ==
false, non-NULL == true.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to