[Asterisk-Dev] FW: asterisk/doc CODING-GUIDELINES,1.4,1.5

Sergey Kuznetsov asterisk_biz at deeptown.org
Wed Jan 19 07:36:30 MST 2005


Andrew Kohlsmith wrote:

>On January 19, 2005 12:00 am, Edwin Groothuis wrote:
>  
>
>>Any C programmer who checks with strlen() if the length of a string
>>is greater than zero should be forced to read the K&R book again
>>to understand how the C programming language actually works.
>>    
>>
>
>Save me a trip to the library and tell me when strlen() would not return the 
>length of a string?
>
>I've been a C programmer for over a decade now and can't think of a reason why 
>this would be considered a bad thing.  At the very heart of strlen would be a 
>loop something along the line of
>
>int count = 0;
>while (*(string++))
>        count++;
>
>Yes my C's getting rusty but can you think of a better/faster way to count the 
>characters in a zero-terminated string?
>
>  
>

If you just want to check if string is bigger than 0, just check:

    if ( *str )
    {
       blah-blah-blah;
       blah-blah-blah;
       blah-blah-blah;
    }

in this case you will save lots on CPU cycles.



All the Best!
Sergey.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20050119/af9d574f/attachment.htm


More information about the asterisk-dev mailing list