> I used macros and tiny structs to track length. In noscrypt I replicated C# spans with inline functions and small structs, the same way literally every other language does because most of them are written in C anyway lol.
the way you say that, C is mostly a language for people with too much time on their hands 😀 it's great if things like that just work with the standard types provided by the compiler/standard library, believe me, after 30 years of coding it doesn't sound like fun anymore to roll it yourself
> storing the termination with 0 at the end of a buffer is arguably the most efficient way to handle that
nah, PASCAL strings (storing the length explicitly) are slightly more efficient in most cases, as there's no need to iterate over the string again and again to get the length.
But their biggest problem isn't efficiency, it's that a character (\0) is special-cased. This can often be exploited in various ways in protocol handling.
(i say this as someone that has found tons of remote exploitable bugs in C code, including libminiupnp 😱 )