[fpc-pascal] Untyped var params
Dmitry Boyarintsev
skalogryz.lists at gmail.com
Wed Jan 4 17:07:17 CET 2017
On Wed, Jan 4, 2017 at 10:24 AM, Ryan Joseph <ryan at thealchemistguild.com>
wrote:
> But how do you assign to “something" then if you don’t know the type? The
> param is “var” so shouldn’t I be able to assign to the param and return it
> back to the caller? In your example how could I return 5 to “i” inside
> GetSomething?
>
> Treat is as a pointer (it's an implicit pointer anyway)
function GetSomething (var something): boolean
var
pi: PInteger;
begin
pi:=@something;
GetSomething:=pi^>=5;
end;
or an old-school way using "absolute".
function GetSomething (var something): boolean;
var
i: Integer absolute something;
begin
GetSomething:=i>=5;
end;
var
i : integer;
begin
i:=3;
writeln(GetSomething(i));
end.
check out "anysort" function
http://wiki.freepascal.org/Array_sort
It's using untyped parameter to perform a sort on an arbitrary type array
thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170104/dc05ac8d/attachment.html>
More information about the fpc-pascal
mailing list