[fpc-pascal] Const params question

Michael Van Canneyt michael at freepascal.org
Wed Oct 11 12:36:13 CEST 2017



On Wed, 11 Oct 2017, Graeme Geldenhuys wrote:

> On 2017-10-11 11:01, Michael Van Canneyt wrote:
>> No, you need constref then.
>
> So for the record.... In the example given, will const make a copy of 
> the record and constref will pass in the original record (no copy of data)?

In the case of const, you don't know. The compiler will do as it sees fit.

In the case of constref, you are forcing the compiler to use a reference
(so no copy of data)

>
> If so, then what's the difference between constref and var? Because it 
> sounds like they are doing the same thing - given the example.

Behind the scenes, at an assembler level, it is using the same mechanism.

The difference is that you can assign something to a var parameter, 
but you cannot assign something to a constref.

Michael.



More information about the fpc-pascal mailing list