[fpc-pascal] Pass open array to static array?

Ryan Joseph genericptr at gmail.com
Fri Apr 3 17:26:09 CEST 2020



> On Apr 3, 2020, at 10:09 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
> 
> No. The "[...]" for an open array parameter means "open array constructer" *not* "dynamic array constructor". And this on-the-fly open array is in fact constructed on the stack. 

Ok, I see now. Excellent. I thought this was another dynamic array being created and destroyed.

> 
> If your DoThis would be declared with a dynamic array parameter (e.G. "specialize TArray<Integer>") then you'd in fact have a temporary dynamic array constructed on the heap. 
> 
> Also I didn't say that dynamic arrays can't be constant, but that they only are so if declared in a const section. 
> 

can you post an example of a const dynamic array? I tried and it thinks it's a set so I can't assign to an open array.

Also that made me think, is it possible for an open array parameter to be written to if its source was a static array? You said it's a pointer so I wonder if it's possible to use them instead of passing a static array pointer with an additional parameter for the length.

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list