[fpc-devel] Looking for clarification on what I think are obviously missing "const" prefixes for parameters in the methods of TRect (the typshrdh.inc one)
Sven Barth
pascaldragon at googlemail.com
Sun Jan 27 10:07:07 CET 2019
Am So., 27. Jan. 2019, 02:53 hat John Doe <slightlyoutofphase at gmail.com>
geschrieben:
> However, I'm also quite simply unaware of any specific realistic scenario
> where I would *ever* specify a un-prefixed record in a method (in my own
> projects for example I actually haven't used anything but "var" and
> "constref" for years, not even just normal const as it doesn't always "do
> the trick" I've found), and I do think that on a more broad scope it is
> highly unlikely that most existing record methods written in an
> "unprefixed" fashion were done that way for any particular or intentional
> reason.
>
As I suggested in my answer one situation is interfacing with non-Pascal
code.
Also there is another side effect that at least needs to be kept in mind:
if you have multithreaded code having one of the by-ref parameter types
across thread boundaries and one thread changing a value (e.g. because it
was passed as "var" there and some other function works with "constref")
will result in the values all threads see to be changed.
This might be quite a constructed scenario, but we do explicitly warn in
the documentation of a similar situation. See the second remark here:
https://freepascal.org/docs-html/current/ref/refsu67.html#x179-20100014.4.4
(the first remark there is also somewhat important as "const" alone
provides no guarantee of being passed by-ref, only that the compiler won't
allow you to write assignments with the parameter or its fields on the left
side).
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190127/e842ca53/attachment.html>
More information about the fpc-devel
mailing list