3 ms·
Those would be Pascal Strings (length at the start, then the bytes). Those make for very easy to write code, but they come with a few issues, but in general the
by dr_zoidberg 5y ago
Those would be Pascal Strings (length at the start, then the bytes). Those make for very easy to write code, but they come with a few issues, but in general they are simpler and give better behavior than null-terminated strings. However, as for a bit of a historical bagagge, it seems we got used to null-terminated strings and just went on with them.
- pjmlp 5y agoOnly in C, even C++ has since the early days adopted proper strings on its standard library, initially the compiler specific ones from the early 90's, then the standard one.
- dr_zoidberg 5y agoSure, its just that these kind of strings were historically called Pascal-strings [0] because they were the way Pascal implemented strings. [0] And still are! For example, Python refers to them as such, see the "p" (lowercase p) character code here: https://docs.python.org/3/library/struct.html#format-strings https://docs.python.org/3/library/struct.html#format-strings
- pjmlp 5y agoNot all C++ string libraries use Pascal strings. Some of them use a fat pointer instead, with a mix of counter, pointer to the end, and null terminator for C compatibility.
- dr_zoidberg 5y agoThat's ingenious, but I don't think I've heard a name for those kind of strings.
- pjmlp 5y agoOne thing is certain, they aren't Pascal strings.