You can replicate the same sort of storage of the string length alongside the buffer itself that other languages have by using structs quite easily.
You can replicate the same sort of storage of the string length alongside the buffer itself that other languages have by using structs quite easily.
The devil is in the "just", though. It is actually a hassle to use counted strings when every one else uses ASCIIZ; you sacrifice interoperability for sometimes dubious performance improvements (and sometimes docs because if you're working on a large lib documenting this exhaustively is... exhaustive and boring - and now your users have two issues with your stuff).
Often you can keep track of the length of strings and use the "mem" functions instead of the "str" functions. printf for instance returns the length of the resulting string. The tools to avoid unwanted quadratic behavior are there, the hard part is often to just notice that you "did it again".
char* s = "foo";
Then that string will be stored as f,o,o,\0 so the convention is baked into literals.