[fpc-devel]Re: Freepascal bug?
Balogh, Karoly (Charlie/iNQ)
charlie at scenergy.dfmk.hu
Tue Oct 14 02:15:06 CEST 2003
Hi,
On 03.10.13., Tamas Konkoly wrote:
> I would like to know why don't work the first d declaration.
> The second declaration work only well, because I checked it.
>
> type TR=record
> a,b,c:longint;
> end;
> var data:array[0..100]of TR;
> procedure pp(var r:TR);
> var d:^TR;
> begin
> d:=@r[20]; // << this is not compileable
> d:=@r+20*sizeof(TR); // << this is compileable
> end;
>
> begin
> pp(data[0]);
> end.
This code is buggy, and shows bad coding too, IMO. The problem is
that r is not an array. The easiest way to fix is some typecasts.
type PTR = ^TR;
d:=@(PTR(@r)[20]); // ugly;
IMO, the above code should look like this:
type PTR=^TTR;
TTR=record
a,b,c:longint;
end;
var data:array[0..100] of TTR;
procedure pp(r:PTR);
var d:PTR;
begin
d:=@r[20];
end;
begin
pp(@data[0]);
end.
Hope this helps.
You can ask me in private mail in hungarian if needed.
Bye,
--
Charlie/iNQ (SceneCON - http://scenecon.intro.hu)
.:%[ Cybernetic Hydraulic Android Responsible for ]%:.
.:%[ Logical Infiltration and Exploration ]%:.
.:%[ Member of TeamOS/2 Hungary ]%:.
.:%[ Member of Hungarian Amiga User Group ]%:.
More information about the fpc-devel
mailing list