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

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



With the info that Gary supplied, I was able to write a macro to get the
address of a C function.  It seems to compile and link fine.

use dylan-direct-c-ffi;  // in fuctional-dylan library

define macro address-of-c-function
  { address-of-c-function (?c-function-name:expression, import:
?import:expression) }
    => { make(<c-function-pointer>,
           address: primitive-wrap-machine-word
                     (primitive-cast-pointer-as-raw
                       (%c-variable-pointer(?c-function-name,
?import)))); }
  { address-of-c-function (?c-function-name:expression) }
    => { make(<c-function-pointer>,
           address: primitive-wrap-machine-word
                     (primitive-cast-pointer-as-raw
                       (%c-variable-pointer(?c-function-name, #f)))); }
end;



It can be used as follows:

address-of-c-function("foo", import: #t);


Sent via Deja.com http://www.deja.com/
Before you buy.



References: