[fpc-pascal] Array as result in function.

silvioprog silvioprog at gmail.com
Sat Jan 21 00:40:23 CET 2017


On Fri, Jan 20, 2017 at 7:11 PM, fredvs <fiens at hotmail.com> wrote:

> Hello Silvio.
>
> Wow, thanks, I will study it deep.
>
> By the way, the Opus Pascal wrappers are working.
> You may listen, seek, saving to file, apply dsp,.. to Opus files.
> You may try SimplePlayer demo in uos (all libraries and Opus-audiofile
> included):
>
> https://github.com/fredvs/uos
>
> PS: BufferIn is working only if it is a array of cfloat (from ctypes.pas).
> With array of double, array of float,.. it does not work.


Yes, because C `float`'s size is 4, and Pascal `double`'s, 8. Pascal
`cfloat` is just a alias to `single`, 4. :-) Try two tests:

$ echo -e '#include <stdio.h>\nint main(){printf("size of float: %zu\\n",
sizeof(float));return 0;}' > fredvs.c && gcc -o fredvs fredvs.c && clear &&
./fredvs # it prints "size of float: 4" on your terminal

and:

$ echo "program fredvs;begin writeln('sizeof double: ',
sizeof(double));writeln('size of single: ', sizeof(single));end." >
fredvs.pp && fpc fredvs.pp && clear && ./fredvs # it prints "sizeof double:
8" and "size of single: 4" on your terminal

Some useful links:

FPC Real types:
http://freepascal.org/docs-html/ref/refsu6.html#x28-310003.1.2
C - Data Types: https://www.tutorialspoint.com/cprogramming/c_data_types.htm
Delphi to C++ types mapping:
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Delphi_to_C%2B%2B_types_mapping

Fre;D
>
> -----
> Many thanks ;-)


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


More information about the fpc-pascal mailing list