J
jacob navia
Yes. Instead of writingKeith said:jacob navia said:[...]pemo said:I believe that in languages like Pascal, the length of a string is
encoded in some sort of 'header' data structure, and that if a
programmer wants to know the length of such a string, the resultant
discovery is therefore very fast.
Does anyone know of an implementation that perhaps does something
like this?
Yes, if you download lcc-win32 you will find an implementation of
strings using length prefixed strings. They are treated just like
normal strings, and a replacement for the string functions in the C
library is provided. The library source is distributed with lcc-win32.
http://www.cs.virginia.edu/~lcc-win32
Can this implementation be used with compilers other than lcc-win32?
a[2] = 'a';
you should write
setString(a,2,'a');
and similar things. But in general yes, you could do it.
The objective of the library is to make porting old code very easy
and this can't be done in standard C.
I hope in the new standard edition operator overloading will be allowed,
together with generic functions. Only those two changes are needed to
allow for easy implementation of length delimited strings.