[fpc-pascal] Array as result in function.

silvioprog silvioprog at gmail.com
Thu Jan 19 23:06:53 CET 2017


On Thu, Jan 19, 2017 at 6:50 PM, fredvs <fiens at hotmail.com> wrote:

> Hello.
>
> With this code, the result of the function does not have same format as the
> array input:
>
> Why ?
>
> type
>   TArFloat = array of cfloat;
>
> function array_in_out(arrayin: TArFloat): TArFloat;
> begin
> result := arrayin;
> end;
>

It works fine here. Eg:

=== begin code ===

type
  TArFloat = array of cfloat;

function array_in_out(arrayin: TArFloat): TArFloat;
var
  i: byte;
begin
  for i := low(arrayin) to high(arrayin) do
    arrayin[i] *= 10;
  Result := arrayin;
end;

...

var
  item: cfloat;
  thebuffer: TArFloat;
begin
  SetLength(thebuffer, 3);
  thebuffer[0] := 1;
  thebuffer[1] := 2;
  thebuffer[2] := 3;
  WriteLn('before');
  for item in thebuffer do
    WriteLn(item.ToString);
  thebuffer := array_in_out(thebuffer);
  WriteLn('after x10');
  for item in thebuffer do
    WriteLn(item.ToString);
end;

// output:

before
1
2
3
after x10
10
20
30

=== end code ===


> Some more explaination.
>
> If in a code I use:
> var
> thebuffer: TArFloat;
>
> // thebuffer was filled with some float-samples
>
> thebuffer := array_in_out(thebuffer);
>
> It is not neutral, the data are affected (in audio the data are noisy).
>
> What is wrong ?
>

Are you using that function as callback with some (C/C++) library? If so,
check its parameter calling convention, declaring it as `function
array_in_out(arrayin: TArFloat): TArFloat; cdecl;`.


> Thanks.
>
> Fre;D


-- 
Silvio Cl├ęcio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170119/b8cb2872/attachment.html>


More information about the fpc-pascal mailing list