[Top][All Lists]

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

[Chicken-users] idiom question

From: Peter Keller
Subject: [Chicken-users] idiom question
Date: Thu, 3 Oct 2002 18:37:52 -0500
User-agent: Mutt/1.2i


I have a question concerning an idiom I want to do in the C FFI.

Suppose I have a function like this:

int foo(int bar, int *qux)
        *qux = bar + *qux;
        return (*qux % 2)?0:1;

Now, my question is, how do I design an FFI to the above function that
is concise and nice to use?

My current methods are less than optimal:

(let (  (bar 0) 
                (qux (make-int_p))) ;; uses set-finalizer!
        (set-int_p-val! qux 32) ;; call a c function which does this    
        (let (result (foo bar qux))
                (print "return value " result " and qux is " (deref-int_p 

This is terribly ugly.

Is there a better way? And can this better way generalize to structures?
(I am keeping in mind the structure FFI knowledge that was posted to
this list a while back.)

In the GNU MP FFI, it turned out not to be a problem because the pointers
were totally black box, even in the C api. You NEVER dereferenced them
but always used api calls to inspect them.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]