On Thu, 22 Jun 2023, Hairy Pixels via fpc-pascal wrote:
I've forgotten entirely, what does subscripting a pointer do in Pascal? p[0]
returns 100 but after that garbage. Seems like a c-style array which doesn't
feel right in the language.
var
i: Integer;
p: PInteger;
begin
p := @i;
p^ := 100;
writeln(p[0]);
writeln(p[1]);
writeln(p[2]);
It's for easier pointer math, a construct which has been used in FPC since day
1 (AFAIK).
Use with care, since no boundary checks are done.
Michael.
_______________________________________________
fpc-pascal maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal