[fpc-devel] FPC_HAS_CONSTREF

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Oct 22 13:28:58 CEST 2010


On 22 Oct 2010, at 12:17, Hans-Peter Diettrich wrote:

> Jonas Maebe schrieb:
>
>>> What is "constref",
>> A "const" parameter that is always passed by reference.
>
> What's the guarantee, that (in detail external) subroutines will  
> honor the "const" attribute?

None. "const" (and constref) is a hint from the programmer that the  
argument can be considered by the compiler as "constant" inside the  
called routine. If the called routine is compiled by FPC, FPC itself  
will perform a number of checks that catch the most obvious ways to  
modify const arguments, but there are plenty of ways to work around  
that (e.g., pointers, assembler code, passing a global variable via  
constref and then modifying the global variable directly in the called  
routine, ...).

> 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.


Jonas



More information about the fpc-devel mailing list