Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > function explanation

Reply
Thread Tools

function explanation

 
 
John Bode
Guest
Posts: n/a
 
      09-29-2003
Jarno A Wuolijoki <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> On Fri, 26 Sep 2003, CBFalconer wrote:
>
> > > > What is difficult to understand about...?
> > > >
> > > > while (*s++ = *t++)
> > > > ;
> > >
> > > First, there's an off by one error. Second, it doesn't terminate
> > > the destination string.

> >
> > No there isn't (an error). Yes it does (terminate).

>
> And that's supposed to be easy to understand?
>


Yes, after your brain has been sufficiently damaged^H^H^H^H^H^H^H
trained to recognize certain C idioms.
 
Reply With Quote
 
 
 
 
Jarno A Wuolijoki
Guest
Posts: n/a
 
      09-29-2003
On Mon, 29 Sep 2003, pete wrote:

> > Even an experienced C programmer, though he will not
> > misinterpret it, will probably take longer to read and understand the
> > expression and verify that it is correct.

>
> "... the idiom should be mastered,
> because you will see it frequently in C programs."
>
> Mastering the idiom means, that you will recognize it,
> and know at a glance, what it means.
>
> If you have not mastered it, then it may be tough.
> But the mastery that particular idiom, is more common than not,
> among experienced C programmers.
>
> A few snippets for you:


Note that the "idiomatic strcpy" performed a transgression that
none of your perfectly readable snippets did:

while (loop_body) /*nothing*/ ;

Sure I know what it really does, but then again, I know !strcmp(a, b)
as well.

 
Reply With Quote
 
 
 
 
Kevin Easton
Guest
Posts: n/a
 
      09-30-2003
Jarno A Wuolijoki <(E-Mail Removed)> wrote:
> On Mon, 29 Sep 2003, pete wrote:
>
>> > Even an experienced C programmer, though he will not
>> > misinterpret it, will probably take longer to read and understand the
>> > expression and verify that it is correct.

>>
>> "... the idiom should be mastered,
>> because you will see it frequently in C programs."
>>
>> Mastering the idiom means, that you will recognize it,
>> and know at a glance, what it means.
>>
>> If you have not mastered it, then it may be tough.
>> But the mastery that particular idiom, is more common than not,
>> among experienced C programmers.
>>
>> A few snippets for you:

>
> Note that the "idiomatic strcpy" performed a transgression that
> none of your perfectly readable snippets did:
>
> while (loop_body) /*nothing*/ ;


while (sideeffects) { }

might well be a clearer way of writing it. It's pretty hard to
misinterpret that.

- Kevin.

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      10-01-2003
Kevin Easton wrote:
>

.... snip ...
>
> while (sideeffects) { }
>
> might well be a clearer way of writing it. It's pretty hard to
> misinterpret that.


Which can be used to evolve a fairly efficient strlen:

while (*s++) continue;

Now all we have to know is how many time s was advanced, leading
to:

size_t strlen(char *s)
{
char *p = s;

while (*s++) continue;
return s - p - 1;
}

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need an explanation on a function decoration Onix C++ 3 04-01-2008 03:20 PM
Simple Explanation to Networking Wirelessly?? Jaxim Wireless Networking 4 08-19-2005 05:04 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
explanation Mariusz VHDL 1 01-13-2004 02:10 AM
Need Explanation Kaladhaur Palaniappa Perl 0 08-07-2003 09:47 AM



Advertisments