[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 01:44:01 CET 2019


Am So., 27. Jan. 2019, 00:01 hat John Doe <slightlyoutofphase at gmail.com>
geschrieben:

> Not the right person to give a qualified answer to your question, but bare
> record parameters in method signatures are kind of a problem throughout
> various parts of the standard FPC and Lazarus libraries, I've noticed.
>
> It almost makes me think the either the compiler should perform the kind
> of optimization it does with const/var/constref implicitly no matter what,
> or it should just not allow you to specify methods without them at all.
> What's the point in having a way of doing something that is guaranteed to
> always give worse results than all of the other ways? It seems pointless.
>

No, the default by-value passing has its uses. With "const" and "constref"
one can't modify the record and one needs to make a copy to do so and with
"var" one always changes the passed in reference so one needs a copy if one
does not want that.
Changing this behavior would not only be a backwards incompatibility, but
would also violate the ABI which describes how records shall be passed. And
if it says copy then it shall get copy ("var" and "constref" are
essentially pointers and "const" puts the decision to the compiler and is
not part of the system ABI anyway).

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190127/a29fcbae/attachment.html>


More information about the fpc-devel mailing list