On Oct 15, 2011, at 11:35 AM, Toby Thain <toby at telegraphics.com.au> wrote:
On 14/10/11 11:59 PM, Josh Dersch wrote:
On 10/14/2011 8:23 PM, Toby Thain wrote:
An oft-quoted C idiom (the cuteness of which does
wear off a bit) was
exhibited - apart from in Unix sources - in the K&R book. To
understand it one might have to realise that adding a constant to a
pointer, and dereferencing, is equivalent to p[constant]:
mystery(char *s, char *t) {
while(*s++ = *t++)
;
}
The *(p+c) business cannot remain mysterious if one wants to write
idiomatic C. I would tend to prefer the idiom above to a tedious loop
with counter and []'s written longhand, though a comment might be
warranted.
And I would tend to prefer a loop that involves some sort of bounds
checking :).
But but but OMG THAT WOULD SLOW IT DOWN....
>
>
>
Yes. And if you think about it, that particular change would slow pretty much
everything on the planet down.
While it's convenient, it really amounts to programmer hand-holding. I'm
certainly able to keep track of my own arrays, surely you are as well. ;)
-Dave
--
Dave McGuire
New Kensington, PA