[Ecls-list] Low-level FFI -- dereferencing a C string

Alfred Steffens Jr apsteffe at netwood.net
Fri Feb 1 16:34:48 UTC 2013


I have an ECL interpreter embedded in a C application, linked with 
-lecl.   I have a global string

char name[32];
strcpy(name, "hello");

The C function GetName returns the address of name[],

int GetName()
{ return (int)name); }

I use a c-inline to call GetName from Lisp to return the address.

(defun get-current-address ()
    (ffi:c-inline () () :int "GetName()" :one-liner t))

So, I get the address in Lisp,

    (setq ptraddr (get-current-address))

and create a pointer

    (setq ptr (uffi:make-pointer ptraddr :void))

or perhaps I should use '(* :char) for the type.

This seems to work fine.  But I want to dereference ptr to display the 
string in Lisp.  What am I missing?  Can you show an example?

Al





More information about the ecl-devel mailing list