CBFalconer wrote:
Emil Jerabek wrote:
it seems that GPC ignores the upper bounds of $SUBJ when they are automatically converted to CString:
[pas]% cat slice.pas program Foo (Input, Output);
procedure Bar (S: CString); begin {$local X+} WriteLn (S) {$endlocal} end;
var S: String (20);
begin S := 'failedOKfailed'; Bar (S[7 .. 8]) end. [pas]% gpc slice.pas [pas]% ./a.out OKfailed
Is this part of any standard? or is it yet another extension? The
String slices (and, more generally, array slices) are defined in ISO 10206. CString's (and implicit conversion of String's to CString's) are a GNU extension.
Emil Jerabek
way I handled this in PascalP (a 7185 compiler) was with the extension "dest := array[7 FOR 2]" (which was Doug Fraleys idea, and may still be in HP Pascal). dest should then be of type ARRAY[1..2]. The same construct could be used on the dest side, i.e. "dest[7 FOR 2] := 'OK';" Everything could be checked at compile time for constant indices and lengths, and run time checks were no harder than any other index check.
-- Chuck F (cbfalconer@yahoo.com) (cbfalconer@XXXXworldnet.att.net) Available for consulting/temporary embedded and systems. (Remove "XXXX" from reply address. yahoo works unmodified) mailto:uce@ftc.gov (for spambots to harvest)