[fpc-devel] FPC_HAS_CONSTREF

Martin fpc at mfriebe.de
Fri Oct 22 16:56:47 CEST 2010


On 22/10/2010 15:24, Jonas Maebe wrote:
> On 22 Oct 2010, at 15:09, Martin wrote:
>
>> On 22/10/2010 12:28, Jonas Maebe wrote:
>>>> AFAIK "constref" was invented for passing values to external subroutines, that expect a reference. In how far does "constref" affect the *caller*, in contrast to e.g. "var"? Can constref pass properties, which are not allowed as var parameters?
>>>
>>> Right now it's allowed (if the property uses a getter, the getter is called and its result is put into a temp location whose address is passed), but I think that's a bug in the implementation.
>> Why?
> Because it's not possible to pass a reference to a property.
True, but that only matters if you intend to change the value of the 
property, by changing the value that the reference points to.
const and constref do not make the promise that the refereed value can 
be used to change the original value

If I understand correctly:

const: is merely a hint, without any further promise. It allows fpc to 
assume the receiver is not going to attempt to change  the value. (used 
for ansistring, by omitting increasing the ref count). So, even const 
could pass a reference to a temporary copy, without breaking any 
documented behaviour.

constref: is the same hint, combined with the promise of a reference.
   That is the expectation is that the receiver can read the value via a 
pointer.
   That is also that fpc can act as if the receiver was not going to 
change the value, therefore if the reference points to a temporary copy 
of the value, the documented behaviour is still fulfilled?

Martin




More information about the fpc-devel mailing list