On 03-Aug-2007, at 08:50, Andy Armstrong wrote:
Are we still arguing about program args or am I right in thinking
we've moved on to strings in general?
The hate in question is still xargs. However...
With Pascal strings a function that trims leading spaces has to
return a new string - with C strings you just return a pointer that
has advanced past the whitespace. Makes it much easier to write
parsers &c.
Internally, address/length strings have a little more overhead than
counted or terminated strings, but are more versatile and efficient
than either. The "string pointer" is twice as large, but it avoids
redundant copies and scanning.
The thing is, though, that this is irrelevant to xargs... because
stdcmd parameters are not stored in an internal string format like a
command line or argument vector... its a wire protocol. Programs
using either counted or terminated strings on the wire can
efficiently convert them to address/length strings on read and
generate either from address/length strings on output.
Internally, start/end strings are another possibility, though it
could be argued that this is merely another representation of address/
length strings.
Ultimately, though, something like this structure tends to raise its
head:
struct _buffer {
int size; // size of buffer
int length; // size of data in buffer
#ifdef BUFFERGAP
int gap; // start of gap
#endif
#ifdef RESIZABLE
char *data; // start address of buffer
#else
char data[]; // buffer follows header
#endif
};
struct _string {
struct _buffer *buffer;
int offset;
int len;
};