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

Sven Barth pascaldragon at googlemail.com
Mon Mar 16 07:59:00 CET 2020

Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Mo., 16. März 2020, 07:33:

> Ok, that makes sense now. Dynamic arrays can't be passed to static arrays.
> I
> remember when I tried to make aligned dynamic arrays I got to look around
> in
> the code and it seems plausible you could just make a memcpy call in the
> for dynamic arrays being passed to static arrays. Seems deceptively easy.
> :)

You forget managed types. You can't do a simple Move for them.

> Shouldn't it be a constant array though? I'm not sure how the compiler
> works
> but from the programers perspective I thought I was getting something
> without runtime allocation because the array contained only constant
> values.

It's only a constant array if it's declared in the const section. Inside
normal code it can also contain variables, function calls, just any
expression really.

Though it would be a potential optimization if all entries are constant to
treat it as a constant array. Again that is something that *could* be done,
but is not right now.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20200316/b3e607fa/attachment.html>

More information about the fpc-pascal mailing list