[fpc-pascal] When to use and not use @?
Michael Van Canneyt
michael at freepascal.org
Sun Sep 10 00:36:05 CEST 2017
On Sun, 10 Sep 2017, Bo Berglund wrote:
> Coming from Delphi I am a bit confused about the syntax when dealing
> with procedure arguments specified as var...
FPC is exactly the same regarding this.
>
> In Delphi this is all taken care of by the compiler and the
> declaration of the procedure tells it how to deal with the arguments.
> Like so:
>
> procedure DoSomething(var Cnt: integer);
>
> called in FPC by:
>
> DoSomething(@MyCount);
No it is not.
>
> But in Delphi it is just:
>
> DoSomething(MyCount);
It is the same in FPC.
>
> OK, I can live with this, but next comes objects and dynamic arrays
> and such...
>
> When is it appropriate to use @ and when should it not be used?
>
> procedure SendData(var Buf: TBytes);
> procedure DigOutStuff(var MyCase: TCaseObject);
>
> Are these also called with @ or something else?
No, why do you think so ?
> I think that in Delphi it is enough to use the variable name in all
> cases.
It is exacly the same in FPC.
The only place where FPC differs from Delphi is when you assign a procedure
to a procedural variable.
Procedure MyProcedure;
begin
end;
Var
p : Procedure;
begin
P:=@MyProcedure;
end.
> Is there an authoritative document describing this for FPC somewhere?
How about the Language reference guide ?
https://www.freepascal.org/docs.var
Michael.
More information about the fpc-pascal
mailing list