2 ms·
the word "null term" appears in the ascii art diagram, that's where the null terminator is. the strlen field is in the portion labelled header. the strlen fiel
by fsckboy 1y ago
the word "null term" appears in the ascii art diagram, that's where the null terminator is. the strlen field is in the portion labelled header.
the strlen field can be moved to where the word "null term" appears, except with a changed semantic of "bytes remaining" so it will go to zero at the right time. now you have a single entity "bytes remaining" instead of two entities, "strlen" and "null" giving a small storage saving (there is an additional null terminator most of the time, right at the end of the string; but this doesn't take up any storage because that storage is not used for anything else)
over and out.
- ranger_danger 1y ago> the word "null term" appears in the ascii art diagram Yes but it does not appear anywhere in the struct that I can see... I would love to be proven wrong though.
- fsckboy 1y agothe string needs a null terminator to be C-string compatible. the trick of putting a count at the end that turns into a null terminator at the right moment will save a byte, regardless of how it is labelled