[fpc-pascal] Subscript pointers

Michael Van Canneyt michael at freepascal.org
Thu Jun 22 15:41:03 CEST 2023

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.


More information about the fpc-pascal mailing list