Originally Posted by
Casey G
I'm used to strings being terminated with a NULL (or NUL - take your pick) character. I've been told that the <type> string defined in string.h is not NULL terminated. How is string length determined without a NULL character? Is a <type> int prefix attached to the string containing a value of the string length? Pascal uses that structure with a <type> char prefix (hence, Pascal strings can only be 255 character long).
Thank you.
Casey
Typically it's done with a struct...
Code:
typedef struct tString
{ char *string;
int size; // used for realloc()
int length; // MyStr.len
int refcount; } // used by garbage collector
String;
As pointed out it is implementation specific but that's the general idea.