News for hackers. Stuff that matters.
Re:Sentinels Can Be Faster by throwaway894345 on Wednesday September 09, 2020 @05:50PM (#24426339)
Probably my fault for phrasing the question ambiguously, but the parent interpreted my question as I intended it to be interpreted. Interfacing with the system libraries is a common enough case for using null-terminated strings.

I'm actually a little curious how what these low-level APIs look like and how "modern" languages handle efficiently converting to null-terminated strings. Do they just copy everything while C/C++/etc would pass a straight reference? Also, what do the underlying syscall APIs look like?

Re:Sentinels Can Be Faster by steveklabnik on Wednesday September 09, 2020 @05:55PM (#24426378)
It's all good. You are 100% right that it's still a good use-case.

And yeah, in Rust we have a separate CString type that's null terminated, so you may need a copy to move between the two worlds. It just depends, if you're only reading, for example, then you can create a pointer + len where the length doesn't include the 0, and that's effectively zero cost.

You got me curious about my days as a kid putting "pascal" in front of Mac System 7 stuff; I believe that it only accepted Pascal strings. I also vaguely remember people doing funny stuff like null terminating pascal strings anyway and then putting the length before the actual pointer so that you get both in one...

Re:Sentinels Can Be Faster by colejohnson66 on Wednesday September 09, 2020 @06:12PM (#24426520)
Weren’t “Pascal strings” limited in that they were only a byte though? So, your string could only be 255 bytes long (conveniently going to a nice round 256 when you add the length byte).
Re:Sentinels Can Be Faster by steveklabnik on Wednesday September 09, 2020 @06:15PM (#24426538)
Yep!