News for hackers. Stuff that matters.
Re:The Most Expensive One-byte Mistake (2011) by _kst_ on Friday April 11, 2014 @02:39PM (#7574627)
Hypothetically, C could use the first `sizeof (size_t)` bytes to store the length. Endianness shouldn't be much of an issue; just use the endianness of the current machine. You don't typically write the NUL terminator when writing a string to a file; similarly, you wouldn't typically write the length field when writing a counted string to a file.

I agree that NUL-terminated strings were the right decision at the time (and aren't that bad now), but there are sane ways to do counted strings.

Re:The Most Expensive One-byte Mistake (2011) by millstone on Friday April 11, 2014 @02:56PM (#7574737)
You piqued my interest, and it looks like NUL-terminated strings in files is actually common. tar, ELF, JPEG, gzip all use them. When the serialization format matches the in-memory format, you can mmap directly into a struct, which is fast and convenient.
Re:The Most Expensive One-byte Mistake (2011) by 1amzave on Friday April 11, 2014 @06:27PM (#7575967)
> When the serialization format matches the in-memory format, you can mmap directly into a struct, which is fast and convenient.

...and a non-starter if you ever have data interchange between differing types of machines.