[fpc-devel] Question on constref
Sven Barth
pascaldragon at googlemail.com
Wed Feb 1 22:43:53 CET 2023
Am 01.02.2023 um 11:30 schrieb Bart via fpc-devel:
> I thought that constref would be OK for that (the word constref
> suggests to me tah the paramter will be treated (by me) to be a
> constant, and that it shall be passed by reference in all cases,
> whereas with a const parameter the compiler decides upon the best way
> to pass it: by value or by reference).
> I tried to find documentation for constref, but all I could find was:
> https://wiki.freepascal.org/FPC_New_Features_2.6.0#Constref_parameter_modifier
> There it says:
> "Note that in general, it should only be used for interfacing with
> external code or when writing assembler routines."
“constref” is guaranteed to pass the parameter by reference. And the
compiler will ensure that it can't be modified as reasonably possible
(as with “const” there are ways to circumvent this, e.g. by passing
around a pointer to the parameter, but the general cases are covered).
> (B.t.w.: Where can I find the official documentation on constref?)
There is no full documentation for that parameter modifier (someone
might want to file a bug report for that), but the documentation for
“const” (
https://www.freepascal.org/docs-html/current/ref/refsu67.html#x183-20700014.4.4
) contains this:
=== doc begin ===
Contrary to Delphi, no assumptions should be made about how const
parameters are passed to the underlying routine. In particular, the
assumption that parameters with large size are passed by reference is
not correct. For this the constref parameter type should be used, which
is available as of version 2.5.1 of the compiler.
=== doc end ===
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20230201/32746225/attachment.htm>
More information about the fpc-devel
mailing list