[Prev][Next][Index][Thread]

Re: FFI question #2: Getting the address of a C function



At 3:15 PM -0400 7/21/00, oodl@my-deja.com wrote:
>Hi,
>
>I'm trying to fill in a C struct with C function pointers.  I want to do
>something like:
>
>   callbacks.function-1 := address-of-c-function("foo");
>
>where foo is the name of C function that is being linked in with the
>Dylan executable as a C library, and "address-of-c-function" is some
>magic compiler functionality that I am hoping that the FFI has.
>
>I know I can get the address of a C function via this:
>
>   define c-address foo-pointer :: <c-function-pointer>
>     c-name: "foo";
>   end;
>
>but I would prefer something shorter though because I have many
>callbacks, and  I don't need for them to be named in Dylan.  I think
>that define c-address macro must use a function that does what I want,
>but I don't know how to get at it.
>
>thanks in advance...

Here's the expansion of the definition of foo-pointer.

   define variable foo-pointer
     = make(<c-function-pointer>,
            address: primitive-wrap-machine-word
                       (primitive-cast-pointer-as-raw
                          (%c-variable-pointer("foo", #f))));

You'll need to use the dylan-direct-c-ffi module from 
functional-dylan to access the definitions above.  (The second 
argument to %c-variable-pointer is the value of the import: option to 
c-address-definer.)

   - Gary Palter,
     Functional Objects, Inc.


References: