<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Am 01.02.2023 um 11:30 schrieb Bart via
fpc-devel:<br>
</div>
<blockquote type="cite"
cite="mid:CAMye31xk=F24HVywbLb-E9ZPS0SO3GEgTd8nXZfqYkomYCDe4w@mail.gmail.com">
<pre class="moz-quote-pre" wrap="">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:
<a class="moz-txt-link-freetext" href="https://wiki.freepascal.org/FPC_New_Features_2.6.0#Constref_parameter_modifier">https://wiki.freepascal.org/FPC_New_Features_2.6.0#Constref_parameter_modifier</a>
There it says:
"Note that in general, it should only be used for interfacing with
external code or when writing assembler routines."</pre>
</blockquote>
<br>
“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).<br>
<blockquote type="cite"
cite="mid:CAMye31xk=F24HVywbLb-E9ZPS0SO3GEgTd8nXZfqYkomYCDe4w@mail.gmail.com">
<pre class="moz-quote-pre" wrap="">(B.t.w.: Where can I find the official documentation on constref?)
</pre>
</blockquote>
<br>
There is no full documentation for that parameter modifier (someone
might want to file a bug report for that), but the documentation for
“const” (
<a class="moz-txt-link-freetext" href="https://www.freepascal.org/docs-html/current/ref/refsu67.html#x183-20700014.4.4">https://www.freepascal.org/docs-html/current/ref/refsu67.html#x183-20700014.4.4</a>
) contains this:<br>
<br>
=== doc begin ===<br>
<br>
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 <span class="cmtt-10">constref
</span>parameter type should be used, which is available as
of version 2.5.1 of the compiler.
<br>
<br>
=== doc end ===<br>
<br>
Regards,<br>
Sven<br>
</body>
</html>