[kmf-discuss] kmf code review (part I.)

Darren J Moffat Darren.Moffat at Sun.COM
Tue Feb 12 10:10:19 PST 2008


Wyllys Ingersoll wrote:
>> 	Never use the boolean negation operator (!) with non-boolean
>> 	expressions. In particular, never use it to test for a NULL pointer or
>> 	to test for success of the strcmp function, e.g.,
>>   
> 
> I disagree with a lot of our cstyle rules.  I don't understand why it 
> should be a problem to use a
> negation operator with strlen, the result is obvious.  The semantics of 
> strlen (or strcmp either)
> are never going to change.  The internet would probably collapse in a 
> smoldering heap if it
> did :)

!strcmp() is almost always wrong because strcmp returns 0 when the 
strings match.  The !strcmp() is a common programming mistake.

As for !strlen() that isn't a construct I've seen much but I read it as 
"the string has no length" which is I think what you mean.

-- 
Darren J Moffat


More information about the kmf-discuss mailing list