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.

Giuliano

--
Do not do to others as you would have them do to you.They might have different 
tastes.

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

Reply via email to