After reading the article "Back to Basics" by Mr.Spolsky I have thought about string structure in C, that converges most of advantages of Pascal-style string (with length byte) and classic ASCIIZ-strings in C and reduces most of their disadvantages. The main demand is to make this new string effective in machine commands. (for this task I assume, that every character is single byte. Excuse me. :) )
My idea is to store strings (that also can contain zero bytes) in byte array of such structure:
- 0 - length in bytes of string length presentation (value is 1 or more);
- 1..presLength+1 - string length presentation (1 or more bytes; may have fixed length (that processes simpler, but determines string length limit) or not);
- presLength+2..arrrayLength - string content.
I expect this approach can solve most of the problems noticed by Mr.Spolsky, but suppose, that there are some lacks. I want to know you opinion. What do you think about it?