[fpc-devel] Question on constref
Sven Barth
pascaldragon at googlemail.com
Thu Feb 2 11:26:58 CET 2023
Adriaan van Os via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am
Do., 2. Feb. 2023, 09:57:
> Sven Barth wrote:
> > Adriaan van Os via fpc-devel <fpc-devel at lists.freepascal.org
> > <mailto:fpc-devel at lists.freepascal.org>> schrieb am Do., 2. Feb. 2023,
> > 02:47:
> >
> > Sven Barth via fpc-devel wrote:
> >
> > > 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 ===
> >
> > On debate, see FPC issue 17442.
> >
> >
> > There is no debate planned for this in the near future. So even if this
> > might change some time in the future it does not *now* and very likely
> > also not for 3.4.0. Not to mention that things wouldn't change for most
> > platforms anyway, because they only have the platform ABI available and
> > that *must not* change for compatibility with C code.
>
> "Will not change" and "ABI" are non arguments. They do not address the
> questions put forward here:
>
> - under what circumstances (and in what compiler mode) does FPC pass large
> (say 1 MB or 1 GB)
> "const" parameters by value (which is extremely inefficient) ?
> - for what reasons ?
>
> As long as these questions are not addressed and cleared and documented
> "const" parameters are not
> a useable in actual code.
>
We do not document these on purpose, because they're mainly dictated by the
platform ABI (on the majority of targets FPC supports simply the C ABI is
used). The main part of "const" is that you can't (easily) modify the value
and that reference counting isn't done when passing the value around.
Whether it's passed by-value or by-reference is irrelevant for that.
If you need pass-by-reference then use those modifiers that are intended
for them, namely "var", "out" and "constref".
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20230202/3790d998/attachment.htm>
More information about the fpc-devel
mailing list