Ondrej Pokorny via fpc-devel <fpc-devel@lists.freepascal.org> schrieb am Do., 2. Feb. 2023, 10:06:
> On 02.02.2023 07:42, Sven Barth via fpc-devel wrote: > > 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. > > Maybe I am missing something, could you please explain why > IInterface.QueryInterface needs constref? > This isn't about Delphi, but about Windows (and XPCOM): there the IID parameter is declared as "REFIID" which is essentially a pointer. On x86 with stdcall this is not a problem, because there "const TGUID" will be passed as reference, same on x86_64 and also ARM64. However on ARM this is *not* the case (and which is how that issue was discovered). So to avoid having to add a cast to a PGUID to every QueryInterface call we instead decided to introduce "constref" which results in fewer modifications for existing code. Maybe somebody knows a real use case? > There are cases were you really need a reference and want it to be const. Or were you want to avoid a copy *for sure* (e.g. Embedded targets). Only because you can't see a reason for it doesn't mean that it doesn't exist. Regards, Sven >
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel