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.
--Toby
And I would tend to prefer a loop that involves some sort of bounds
checking :).