Giuliano Colla via fpc-pascal <fpc-pascal@lists.freepascal.org> schrieb am
Mi., 12. Apr. 2023, 22:54:

> Il 12/04/2023 21:17, Bo Berglund via fpc-pascal ha scritto:
>
> And if so, what is the rule for **when** to use var in function call argument
> lists for items that will be changed inside the called function and used
> afterwards?
>
> Your Wargs is defined as an open array, i.e. its length is unknown at
> compile time. Therefore the compiler cannot pass it in the subroutine call
> other than a pointer to the array. It cannot pass the array content because
> it doesn't know its length.
> In that case you may omit the var specifier.
> But if one day you change your mind, and decide to establish a size for
> your array, without var the compiler may decide to pass the full array data
> to the procedure, and therefore whatever you do in your procedure is done
> on the local copy of the array and not in the original array.
> My suggestion is to specify "var" whenever your procedure is expected to
> modify the data passed. It makes the program more readable, even if "var"
> is redundant.
>

There is *no* open array in the example given. Also even if there were
changing the length of an open array would not work...

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to