[fpc-pascal] Need three things

Daniël Mantione daniel.mantione at freepascal.org
Sun Aug 12 09:22:20 CEST 2007



Op Sun, 12 Aug 2007, schreef ik:

> > Ok, one more: 4) I miss array slice syntax (str:=3D s[2..7];) from the =
Stony
> > Brook M2 days. So much more concise than Copy().;
> =

> Let me please quote Marco and say "this is a synthetic sugar", or at
> least sort of.. it's not like there is no way (without creating your
> own function) to do this... but if you really want, please write all
> the pro and cons about it, and if people will think that the pro's are
> better then the cons' I sure that more people will agree...

It is supported in FPC 2.2. The reason to support it is not the =

syntactic sugar aspects, but to allow passing dynamically allocated =

memory.

I.e. if you have a:

procedure sort(var a:array of word);

... and some dynamically allocated memory, a call to sort can be done =

like:

var p:Pword;

begin
  getmem(p,2000*sizeof(word));
  {.......}
  sort(p[0..1999])
end;

As there is no other way to do this, array slices are a usefull addition =

to the language. It also looks like they will allow better optimization in =

the future, because the compiler knows more information in advance, like =

wether the ranges can overlap or wether the data to be moved is already =

aligned.

Dani=EBl


More information about the fpc-pascal mailing list