4 ms·
Yes, that's "just" a standard library convention, not a feature of the language itself. The devil is in the "just", though. It is actually a hassle to use coun
by astrobe_ 4y ago
Yes, that's "just" a standard library convention, not a feature of the language itself.
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".
- tragomaskhalos 4y agoTo be pedantic, if I do char* s = "foo"; Then that string will be stored as f,o,o,\0 so the convention is baked into literals.