[fpc-pascal] Blockread blockwrite var vs out parameters
Jonas Maebe
jonas.maebe at elis.ugent.be
Wed Dec 16 11:55:50 CET 2015
Santiago A. wrote on Wed, 16 Dec 2015:
> In functions blockread and blockwrite, the result parameter is "var".
> And in blockread buffer is also "var".
>
> Couldn't they be marked as "out" instead of "var"?.
The result parameters can be changed. The BlockRead buffer parameter
cannot be changed for the same reason that the parameters of fillchar
and move cannot be changed: it changes the behaviour in case a managed
type, or e.g. a record or array containing managed types, it passed.
With "var", nothing special happens, while with "out", they are first
finalised. If they are not yet initialised at that point (e.g. because
they are the result of a plain getmem), this would introduce crashes.
Even though you cannot just blockread/blockwrite managed types anyway
(since they are pointers), this can currently work if you ensure that
all read/written managed types are nil. It may seem unlikely, but at
least changing the "var" parameters of move/fillchar to "out" even
caused crashes in the compiler because the RTL relies on the current
behaviour (and using move/fillchar with managed types is not very
common/recommended either in the general case).
Jonas
More information about the fpc-pascal
mailing list