On Thu, 2 Feb 2023, Sven Barth via fpc-devel wrote:

Am 02.02.2023 um 02:09 schrieb Hairy Pixels:

On Feb 2, 2023, at 4:38 AM, Sven Barth <[email protected]>
wrote:

Which types are passed by-value or by-reference when using const is
determined by the size of the record and the types of the fields based on whatever the corresponding ABI defines (e.g. the x86_64 Sys V ABI is rather explicit about some field combinations). The compiler will however not switch between passing a specific type once by-value and another time by-reference.
So if the compiler is making the choice using const which is more efficient
then we should be using const always I would think? What problem does constref solve then?

The case when you *need* a constant reference. Case in point: the passing of TGuid in IInterface.QueryInterface. Delphi code relies on it being a reference, but “const” does not guarantee that for all platforms.

Exactly. That is why they introduced [ref], which serves essentially the same 
purpose as
constref.

https://docwiki.embarcadero.com/RADStudio/Sydney/en/Parameters_(Delphi)#Constant_Parameters

We were way ahead of them on that particular one. Benefits of being cross-platform since a long time :-)

Michael.
_______________________________________________
fpc-devel maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to