4 ms·
If you want simple, it's hard to beat the original K&R (1978!) while(*p++ = *q++); which is what sold a generation on the whole idiom. Of course its tim
by imglorp 7y ago
If you want simple, it's hard to beat the original K&R
(1978!)
while(*p++ = *q++);
which is what sold a generation on the whole idiom. Of course its time is long gone but useful to learn.
- dwheeler 7y agoThis construct: while(*p++ = *q++); is simple. But I agree with you, its time has long gone, because in many programs, this code is also wrong. This idiom assumes that that the source can never be longer than the destination. There are now a legion of attackers who will exploit this code and harm its users. Modern C programs often have to work in the presence of attackers.