3 ms·
The idiomatic void strcpy(char *s, char *t) { while (*s++ = *t++) ; } (straight from K&R) wouldn’t work without it.
by layer8 2y ago
The idiomatic
void strcpy(char *s, char *t)
{
while (*s++ = *t++)
;
}
(straight from K&R) wouldn’t work without it.
- n_plus_1_acc 2y agoWhich many people find unreadable compared to other versions.
- beeforpork 2y agoAnd for several reasons. * is it (*s)++ or *(s++)? * it is not *++s nor ++*s And I have seen *(*s)++ in some places! It is concise syntax but very confusing.
- chongli 2y agoK&R actually teaches this as a desirable idiom? People should not be recommending K&R to beginners today!
- trealira 2y agoKernighan spends a page whittling strcpy down to just that, with various intermediate versions. After showing you that version, he describes it like this: Although this may seem cryptic at first sight, the notational convenience is considerable, and the idiom should be mastered, because you will see it frequently in C programs.