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

Christos Chryssochoidis c.chryssochoidis at gmail.com
Wed May 23 10:36:20 CEST 2007

On 23 Μαϊ 2007, at 11:11 ΠΜ, Daniël Mantione wrote:

> 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_______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Yes, I have noticed that if you first wrap a dynamic array in a type  
definition then you can declare a function returning such an array,  
but it seemed to me as an unnecessary complication of things and as  
an inconsistency in the language. However, the distinction between  
dynamic and open arrays that D.Mantione says, explains this  

Thanks very much for your answers,


More information about the fpc-pascal mailing list