4 ms·
Maybe that's not the whole picture, but I think a big reason for null terminated strings is that C has pointers. A char pointer makes it practical to move throu
by coliveira 11y ago
Maybe that's not the whole picture, but I think a big reason for null terminated strings is that C has pointers. A char pointer makes it practical to move through strings and a NULL terminator is easier to handle than a size test. In the end, sized strings make C code more complicated, unlike other languages such as Pascal.
- pjmlp 11y agoWhich also has pointers, yet makes use of safe strings.
- coliveira 11y agoTrue, I should have said pointers and pointer arithmetic. In Pascal you cannot do these things because there is no pointer arithmetic to move along strings and arrays.
- pjmlp 11y agoOnly if you are speaking about the boring ISO Pascal. All Pascal dialects like Apple Pascal and Turbo Pascal had pointer arithmetic.
- coliveira 11y agoThat was an extension to the Pascal language, it doesn't really change the way to write idiomatic code.
- pjmlp 11y agoMoving goal posts are we? Should I list all the compiler specific features that everyday C programmer uses but aren't defined in ANSI C, e.g. inline assembly? No professional Pascal compiler was a pure ISO Pascal, that error was left for schools teaching bad Pascal. Professional Pascal compilers were way more powerful than C, safer and in the days of K&R C chaos, just as portable.
- coliveira 11y agoI have made no comment about the quality of Pascal vs. C. In fact I like Pascal a lot, my comment is just on the way to write idiomatic code in each language. In C it is much easier and common to traverse data structures. Pascal may do it in some implementations, but its not how programmers used to organize their code. This just means that for C programmers it is frequently easier to work with NULL terminated strings.