|
|
|
|
|
by adwn
1779 days ago
|
|
> it is kind of wrong to blame the tool for the mistakes made by the one wielding it I strongly disagree. I think it is absolutely legitimate to blame a tool which is practically impossible to use correctly [1]. Some of C's design decisions were justified in its historical context, and some – like zero-terminated strings – were indefensible even back then. [1] Alternatively, you could blame its creators, but that's not very useful. |
|
Snippet from "https://dave.cheney.net/2017/12/04/what-have-we-learned-from...":
One can write a string copy routine using two instructions, assuming that the source and destination are already in registers.
The routine takes full advantage of the fact that MOV updates the processor flag. The loop will continue until the value at the source address is zero, at which point the branch will fall through to the next instruction. This is why C strings are terminated with zeros.