1

If I pass a variable as a constant does it automatically get passed by reference?

procedure foo(const x : integer)

I can already pass a variable by reference like this:

procedure foo(var y : integer);

Ideally I'd want something like the code below:

procedure foo(const var z : integer)
J_Strauton
  • 2,270
  • 3
  • 28
  • 70

1 Answers1

2

const does not guarantee that the value is actually passed by reference.

Free Pascal supports

procedure foo(constref z : integer);

for this purpose: z is always passed by reference in this case. I'am not aware of something similiar in other pascal compiler.

FPK
  • 2,008
  • 13
  • 19
  • Out of curiosity, recent Delphi compilers (since Delphi XE4) uses the [`[Ref]`](http://docwiki.embarcadero.com/RADStudio/XE4/en/Parameters_%28Delphi%29#Constant_Parameters) decorator for this. You can write there e.g. `procedure foo(const [Ref] Z: Integer);`. – TLama Dec 12 '14 at 03:59