[fpc-pascal] When to use and not use @?

Bo Berglund bo.berglund at gmail.com
Sun Sep 10 00:18:04 CEST 2017


Coming from Delphi I am a bit confused about the syntax when dealing
with procedure arguments specified as var...

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);

But in Delphi it is just:

DoSomething(MyCount);

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?
I think that in Delphi it is enough to use the variable name in all
cases.

Is there an authoritative document describing this for FPC somewhere?

My current case is sending data from a thread to an event in the main
GUI app where the data are located in a TBytes object and I don't want
to copy the data unneccesarily...
I would like to supply the thread buffer to the event so that the
event procedure can copy the data into a local array and process that.

But if I declare the event procedure without using var I am afraid
that just using the buffer as an argument will make the compiler
*copy* the data into the call and then there will be two copy
operations...


-- 
Bo Berglund
Developer in Sweden




More information about the fpc-pascal mailing list