[fpc-pascal] 2D Dynamic arrays and BlockRead
andrew.bennett at ns.sympatico.ca
andrew.bennett at ns.sympatico.ca
Tue Dec 7 18:37:36 CET 2010
Marc Weustink <marc at dommelstein.net> wrote
>On 3-12-2010 17:26, Jürgen Hestermann wrote:
>> ...
>> STat = Array[0..W-1] Of Single ; { Static array }
>> DST = Array Of STat ; { One dimension dynamic, the other static }
>> D2T = Array Of Array Of Single ; { Two dynamic dimensions }
>>
>> STat always means the address starting with STat[0] (context independend).
>> Also DST always means the address where DST[0].
>
>Nope, there is a difference between DST and DST[0]. DST won't give you
>the first element. You can try this youself with an untyped parameter:
>
>procedure Foo(const AParam);
>begin
> WriteLN(Single(APAram));
>end;
>
>
>You will see a difference between passing DST or DST[0]
>To be safe, for any N-dimension dynamic array always use [0,..,0] to
>pass the first element. To avoid confusion, you can do this for static
>arrays too.
Thanks. I've now got things working. More or less.
But where do I find any of this in the documentation?
Ref 3.3.1 gives an example of a 2-D dynamic array that
looks just like a static array apart from the difference in
copying: no mention of the dramatic low-level differencess.
But then, these differences are part of the implementation
so perhaps they should be in the Programmers' Manual. They
aren't. The Ref example uses the 2-D form of Setlength which
is not to be found in RTL 37.9.309. Complexities are hinted
at in RTL 37.9.52, DynArraySetLength but I am very happy to
heed the warning not to mess with that!
Ref 3.3.1 states that memory for a dynamic array will be
disposed of at the exit of the procedure or function. Um!
In various places, "dynamic array" becomes "dynamical array"
which messes up searching. Somebody should decide which it is!
Andrew Bennett
More information about the fpc-pascal
mailing list