[fpc-pascal] Pass open array to static array?
pascaldragon at googlemail.com
Fri Apr 3 17:09:02 CEST 2020
Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Fr., 3. Apr. 2020, 14:33:
> > On Apr 3, 2020, at 3:43 PM, Sven Barth <pascaldragon at googlemail.com>
> > They are neither. They are simply a pointer to the first element and a
> hidden size argument. For the pointer it is not important where it comes
> from: a single element, a dynamic array, a static array.
> Ah, I see. In the example below the open array is still a dynamic array
> right? As you said earlier dynamic arrays are never constant/static (for
> now at least) and therefore [1,2,3] is a dynamic.
> procedure DoThis(a: array of integer);
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.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal