function explanation

J

John Bode

Jarno A Wuolijoki said:
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.
 
J

Jarno A Wuolijoki

"... 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.
 
K

Kevin Easton

Jarno A Wuolijoki said:
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.
 
C

CBFalconer

Kevin said:
.... 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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top