|
|
|
|
|
by flohofwoe
1779 days ago
|
|
Zero terminated strings make sense when you consider the pecularities of the PDP instruction set. 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. loop: MOVB (src)+, (dst)+
BNE loop
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. |
|
The biggest issue with C isn't its footguns, rather the WG14 unwillingness to provide additional language or library features that would allow for a safer C outside the low level code where it pretends to be a portable macro assembler.