I wonder if Succ/Prev intrinsics should be able to be used over typed pointer types. Just like Inc
/Dec
and maths ( PointerVar+1
and PointerVar-1
).
- http://docwiki.embarcadero.com/Libraries/en/System.Succ
- http://www.freepascal.org/docs-html/rtl/system/succ.html
These only apply succ/pred to "ordinal types" which pointes are not listed a part of. So does Pascal Report 1972 (calling it Scalar Types)
However http://www.gnu-pascal.de/gpc/Succ.html#Succ claims "Application of Succ to pointers is defined in Borland Pascal." and it seems not reasonable to exclude those functions in the wake of Pointers Math.
Is this restriction substantiated language-wise or just an implementation problem, seeing Succ/Pred functions are seen as somewhat arcane?
program Project9; // Delphi does have reverse-analogu for Pos/PosEx functions
{$APPTYPE CONSOLE} // So Delphi IDE ( Version Insight) to cut away a last part
uses // of string abuses mixing of record helper (LastIndexOf)
System.SysUtils; // and System.Copy function. Searchinf to fix it found this...
var
OutPut, RemoteName: string;
P: PChar;
begin
try
OutPut := 'aaaaaa/zzzzzz';
P := StrRScan( PChar(OutPut), '/');
P := Succ(P);
// XE2: [DCC Fatal Error] Project9.dpr(13): F2084 Internal Error: AV0C068241-R00000000-0
// 10.1: [dcc32 Error] Project9.dpr(13): E2008 Incompatible types
P := 1+P; // Another way to say Succ() - and works in both XE2 and 10.1
Inc(P); // Yet one more way to say Succ() - and works in both XE2 and 10.1 too
RemoteName := P;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Interesting to compare it with changed var type - P: Pointer;
rather than PChar.
var P: Pointer; S: String;
P := Succ(P); // error
Inc(P); // error
P := 1+P; // works in XE2 if {$POINTERMATH ON}, error if {$POINTERMATH OFF}
// error in 10.1 regardless
S := PChar(P); // crashes XE2 if "P := 1+P;" is there above