[fpc-pascal] Dynamic array as return type of functions

Daniël Mantione daniel.mantione at freepascal.org
Wed May 23 10:11:01 CEST 2007



Op Wed, 23 May 2007, schreef Michalis Kamburelis:

> Christos Chryssochoidis wrote:
> > Hi, 
> > 
> > I tried to write some function that returned a dynamic array, and
> > realized that this isn't allowed. Why? After all one can specify an
> > array of variable length as type for variables... Furthermore - if I'm
> > not mistaken - a dynamic array is implemented internally as a pointer,
> > and so there wouldn't be any runtime overhead for returning a dynamic
> > array from a  function.
> > 
> 
> It *is* allowed. The only trick is that you have to declare a type for
> your dynamic array, i.e. you have to write something like

I think this is one more example open array versus dynamic array 
confusion. Arrays declared in type statements are dynamic arrays; arrays 
declared in procedure/function headers are open arrays. You can return a 
dynamic array, but not an open array.

Daniël


More information about the fpc-pascal mailing list