Re: "C-pointers in FFI" question
Genady Veytsman writes:
>
> Hello,
>
> I can't figure out how to use C-pointers in Stk.
> Could anybody help me?
>
> Here is an example:
>
> Let's say there is C function "printhello" in library
> "libhello" and it returns pointer wich was declared in
> C as:
>
> double* pSignal;
>
> In STk script I write:
>
> (define-external phello()
> :return-type :dynamic-ptr
> :entry-name "printhello"
> :library-name "libhello"
> )
>
> (define p (phello))
>
> Now "p" contains all the data I need, but
> how do I access array's elements?
>
> Thanks in advance
The main idea behind C pointers in Scheme is that you can pass them to
functions but you cannot dereference them. This is useful when you
have function such as fopen which returns a pointer to an object
that you must pass back to all to functions such as fread, fprintf,
fscanf, ... In this case you don't need to dereference the pointer
returned by fopen. Permitting dereferencing pointers is far more
complicate, since most of the time it is a pointer to a structure, and
in this case we'll need a way to express how to access (dynamically) a
C structure. If the pointer is on a structure, you'll have to write a
C function which allows te access the fields of the structure.
In your case, this is not a structure but a predefined type,
and perhaps I should provide a builtin way to do that, but this is not
the case yet. So, you'lll have to write a conversion function C which
takes a C ppointer and return a Scheme float.
-- Erick
Received on Tue Apr 24 2001 - 13:57:06 CEST
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST