Subject Re: udf's by value (by reference?)
Author vogonjeltzprostetnic
--- In firebird-support@yahoogroups.com, Paul Vinkenoog <paul@...> wrote:
>
> These two functions are perfect examples of returning by value.
> Returning by reference is useful if you want to be able to return null
> pointers, which is clearly not the case here.
>
>
> Hope this helps,
> Paul Vinkenoog
>

Thanks, Paul. I don't have anyone on hand to confirm the validity of
my by-value UDF's, and so I appreciate the vote of confidence on that.

I've tried a couple of additional functions that attempt to return by
reference:

library DangerfieldLib;
.
.
.

type
PSmallint = ^Smallint;

function dsbTrueByRef: PSmallint;

const
Returned: Smallint = -1;

begin
Result := @Returned;
end;

function dsbFalseByRef: PSmallint;

const
Returned: Smallint = 0;

begin
Result := @Returned;
end;

exports
.
.
.
dsbTrueByRef,
dsbFalseByRef;

begin
end.

I realize it doesn't ordinarily do to pass pointers to just any data
(issues of threading, memory management, etc.), but I wagered that
passing the address of an object pascal typed constant would be safe
enough, at least to illustrate. Seems to work, in any case:

SQL> declare external function dsbTrueByRef
CON> returns smallint
CON> entry_point 'dsbTrueByRef'
CON> module_name 'DangerfieldLib';
SQL>
SQL> select dsbTrueByRef() from rdb$database;

DSBTRUEBYREF
============
-1

SQL>
SQL> declare external function dsbFalseByRef
CON> returns smallint
CON> entry_point 'dsbFalseByRef'
CON> module_name 'DangerfieldLib';
SQL>
SQL> select dsbFalseByRef() from rdb$database;

DSBFALSEBYREF
=============
0

SQL>

Once again, thanks for your response.

-Marc Benedict