[fpc-pascal] dynamic array contents and system.move

Jürgen Hestermann juergen.hestermann at gmx.de
Sun Apr 25 18:24:02 CEST 2010



>> But currently move *does* handle dynamic arrays differently than other procedures.
> It handles it exactly the same as any other function/procedure that takes a untyped/formal "var" parameter. Formal var parameters always take on the address of whatever you pass.

That's not true! There is a lot of ambigouity with dynamic arrays. Although an underlying pointer is used internally you use it as if it was the array this pointer is pointing to in your code. If you first have a static array "MyArray" then convert it to a dynamic array you don't have to change your code (except if you use fillchar and/or move). Why that? What exactly does "MyArray" mean? You can't tell because it is context dependent. That's not in the spirit of Pascal.

> The confusion comes from the fact that a dynamic array, just like ansi/wide/unicodestrings and a Delphi-style classes/interfaces, is an implicit pointer to the actual data. Hence, if you pass a variable of such type to a formal var parameter, you are passing a pointer to this implicit pointer as the parameter value (rather than a pointer to the actual data).

True. As I said: There is no common logic what the identifier "MyArray" means if it is a dynamic array (but there is for static arrays).

> fillchar() and move() are equivalent to direct assembly level programming as far as the abstraction level is concerned because they ignore all type info. The fact that they ignore all type info is a mess.

It's true that it ignores all *type* info. Still there was no ambigouity about the starting address of a variable you give as parameter until dynamic arrays were introduced (including AnsiStrings).



More information about the fpc-pascal mailing list