returned pointer to an array doesn't work
Original Reporter info from Mantis: skalogryyz
-
Reporter name: Dmitry Boyarintsev
Description:
{$ifdef fpc}{$mode delphi}{$endif}
{$ifdef MSWindows}{$apptype console}{$endif}
uses
SysUtils;
type
PByteArray=^TByteArray;
var
g : array [byte] of byte;
function GetArray: PByteArray;
begin
Result:=@g[0];
end;
var
p : PByteArray;
begin
g[0]:=0;
g[1]:=1;
g[2]:=2;
//FPC won't compile: Error: Illegal qualifier
// Delphi compiles the line fine.
// p:=PByteArray(@GetArray[1]);
// following won't compile as well
// p:=PByteArray(@(GetArray)[1]);
// p:=PByteArray(@(GetArray[1]));
// workaround:
p:=GetArray;
p:=PByteArray(@p[1]);
// p is PByteArray starting at g[1], so @p[1] = @g[2]
writeln(p[1]); // must print 2
end.
Mantis conversion info:
-
Mantis ID: 16772
-
Version: 2.5.1
-
Fixed in version: 2.6.0
-
Fixed in revision: 15475 (#e3685774)
-
Monitored by: » Aleksey Elin (Aleksey Elin)