Grant Jacobs wrote:
Intuition tells me that CString is a 'C' string, as in the programming language 'C' (or a 'char *' if you want the C type definition).
Yes. And also compatible to BP (there called `PChar' which GPC also accepts).
In C, these can be treated as either pointers or as character arrays (to cut a long story short). They are terminated with a \0 (if used correctly, that is: one of the "standard" buggy things to do in C is lose the terminating \0 which can cause all sorts of trouble. The Dest[size] := #0 example you gave is doing the "safe" thing of insisting that the string be terminated correctly.).
Its almost certainly compatible with Apple's CStringPtr = ^char ; as the point of these is C compatibility usually...
Usually characters are byte-sized in C. There are also wide characters, but that's another story again...
But we can want for Frank's definitive answer and the usual nitpicking of my sloppy answer :-|
That's correct. Also GPC automatically "converts" strings to CStrings (by appending to #0 when necessary and taking the address). But it doesn't (usually) copy the string, so the CString will remaing valid only as long as the string is not modified. Usually this is used to pass string values to C routines (which should not modify the CString, either).
Peter N Lewis wrote:
BTW, I noticed in string.pas
if (s2 = nil) or (s2^ = #0)
I know GPC defaults to always doing short circuit, but would that be better written or_else?
Call it laziness, but there are many such places. I think the code becomes more readable (and a little easier to write when one doesn't have to consider whether `or' can be safely used or `or_else' must be used) ...
Frank