According to Frank Heckenbach:
s:='' should do the same. (BP optmizes this to just setting the length to 0, I hope gpc does as well.)
It does. (But better check it, too - I already was wrong once with statements of this type.;-)
I think it should (at least with {$X+} or such), because it's the only way to translate some kinds of procedures -- unless one wants to limit such procedures to borland-like short strings.
Long strings: "S.length:= ...". Short strings: "S [ 0 ]:= chr ( ... )".
The question is, should the #0 be added for short strings as well? If Length=Capacity, it's impossible, but otherwise???
We could increase the space allocated for a short string by 1, but this would break compatibility to UCSD and Borland Pascal. So better ignore this and live with "String [ 255 ]" having only a capacity of 254 in fact.
Currently the length could probably be changed by writing to s[1-SizeOf(Integer)] .. s[0] -- but I really don't want to try that... :-|
No. This will only work for lenghts below 256 and on big-endian machines. Better cast the String to a record (read: cast a pointer to the String to a pointer to a record).
BTW: Does the standard require range checking (or does it say anything about it at all)?
Yes, AFAIK.
And with {$X-} they don't work at all, you mean? Seems ok. And the same for packed records?
Yes.
Isn't it good when non-standard compilers (BP) use non-standard syntax? :-)
I would not call this "non-standard" since this - like many other things, e.g. Units - was not invented by Borland but by UCSD.
BTW: String[n] with n>255 wouldn't work at all then?
Yes.
Greetings,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201] maintainer GNU Pascal [970420] - http://home.pages.de/~gnu-pascal/ [970125]