[fpc-pascal] Why use pointers to arrays?

"Vinzent Höfler" JeLlyFish.software at gmx.net
Mon Oct 12 00:25:29 CEST 2009


Andrew Brunner <andrew.t.brunner at gmail.com>:

> 1st benefit:
> 
> declaring methods associated with classes before TIntArray needs to be
> defined or declared.
>   eg. procedure DoSomething(Var Data:TIntArray); vs (DataP:PIntArray);

Huh? Is there any difference other than the second one can take a NIL value?

> Lastly, passing by reference rather than by value is much faster.

That's what "const" has been invented for: Letting the compiler decide the most efficient way.

Not to mention, expressing your intent:

You don't change it, say so: "const".
You change it,       say so: "var".
You initialize it,   say so: "out".

If you just take the pointer no-one knows if the value is in/in out/or out. That's clearly not a "benefit".


Vinzent.
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01



More information about the fpc-pascal mailing list