According to Jesper Lund:
According to myself (Peter Gerwinski):
According to Extended Pascal, strings are written with parentheses ("Str255 = String ( 255 )"), but GPC also accepts UCSD/Borland syntax ("Str255 = String [ 255 ]"). In the future we *might* change this such that GPC produces an Extended Pascal string (unlimited length, 8 bytes overhead) with "(...)" but a Borland Pascal string (limited to 255 chars, 1 byte overhead) with "[...]".
Wouldn't that feature (choosing between two memory allocation/outline schemes for strings) create a lot of problems for relatively little benefit?
First, if I have a procedure with a var string type,
procedure foo (var s : string)
can I pass variables of either string type (Borland or Extended)?
No, but you can pass them to
Procedure Foo ( S: String );
or to
Procedure Foo ( Const S: String );
Second, a string variable in Borland Pascal does not contain information about the maximum length (like the capacity field in GPC), so for procedures that need this information (like Readln), the string capacity would have to be passed as an implicit parameter (or am I missing something?).
I thought about letting it overflow silently, but passing the capacity as an implicit parameter would be a good idea, indeed.
Finally, and most importantly, why is feature this needed in the first place? [...]
- A program reading string variables from a binary file created by a
Borland pascal program (.exe file). [...]
I agree that this would not really be an issue.
- GPC "wastes" more memory than Borland Pascal [...].
This is one reason why I think that `ShortString's are desirable. The 8 bytes do certainly not matter in, say, a text processor handling strings with a typical length of 100; they do matter in a program that handles a large number of short strings with a typical length of 8. In this second case, an overhead of 8 bytes would double the needed amount of memory.
But I'd like to add:
3) There are many programs written for Borland Pascal and/or Delphi waiting to be ported to GPC, many of which relying on the data format of strings in UCSD/Borland Pascal/Delphi in merely two cases: (a) explicit manipulations of `S [ 0 ]' (one may consider them broken, but they are *many*)-:, and (b) calculations of the current size as `length ( S ) + 1'.
There already was a discussion about a `ShortString' type for GPC on this list in May 1997. The conclusion was to make it compatible to Borland's `String' type like other Extended Pascal compilers and Delphi do.
Greetings,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [971005] maintainer GNU Pascal [971001] - http://home.pages.de/~gnu-pascal/ [971005]