3 ms·
C has _only_ pointers for variable size things, not just strings. Roughly speaking C vars are either known fixed length, or accessed via pointer. There is not
by emmelaich 7y ago
C has _only_ pointers for variable size things, not just strings.
Roughly speaking C vars are either known fixed length, or accessed via pointer. There is nothing else.
(except arrays -- which are mostly pointers)
- doboyy 7y agoThe thing you are pointing to could have its length prefixed. I've always assumed that this isn't the case because nobody could commit to the size of the length prefix. Is it string8, string16, string32, or string64? Using a sentinel value to denote length is less opinionated and more portable.
- jstimpfle 7y agoAnd also unbeatable in memory efficiency.
- doboyy 7y agoUnfortunately, it's often algorithmically less efficient and more error prone, so everybody ends up replicating what git is doing with 'strbuf' but in slightly incompatible ways. The effect makes dealing with strings in C unnecessarily unpleasant.