void strcpy(char *s, char *t) {
while (*s++ = *t++);
}
It's short, elegant, and quite readable to the trained eye–a bit sharp too, but if you use it right it's quite functional. void strcpy(char *s, char *t) {
while (*s++ = *t++);
}
It's short, elegant, and quite readable to the trained eye–a bit sharp too, but if you use it right it's quite functional.I wonder how much damage that code has caused.
This kind of code is cute, but awful for readability. The author could easily (more easily!) have written the function to be very readable, but went for the cute ultra-compact style instead.
The only reason it's at all readable is that it's solving such a simple problem. Write more complex functionality in that style, and you quickly get a nightmare.
I believe MISRA C outright bans this kind of thing (three assignments with no sequence point), as it has no place in a codebase of real consequence.
I understand that some C programmers pride themselves on being able to read this kind of code (far more impressive than being able to write it), but I see no reason for it in serious software work.
Then t would never be able to overflow s (nor even eat its null terminator)
The things you listed are general concerns in C which are unrelated to both the correct implementation and the suggested changes.