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

Wyllys Ingersoll wyllys.ingersoll at sun.com
Tue Feb 12 10:24:14 PST 2008


Darren J Moffat wrote:
> 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.
>   
I have  used that construct in the past, and I agree that it is 
counterintuitive because of
the way strcmp behaves.

> 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.
>
>   
Yes, that is exactly what I mean, it is just a shorthand that I 
sometimes use to mean
"strlen() == 0"

-Wyllys




More information about the kmf-discuss mailing list