On 15/10/2011, at 2: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.
--Toby
And I would tend to prefer a loop that involves some sort of bounds checking :).
And I'd also like a language where a one character addition doesn't change the
function significantly. I read this as a string comparison rather than assignment :-(
Huw Davies | e-mail: Huw.Davies at kerberos.davies.net.au
Melbourne | "If soccer was meant to be played in the
Australia | air, the sky would be painted green"