On 10/15/06, Luís Oliveira <[EMAIL PROTECTED]> wrote:
I don't know anything about how C99 compilers implement the complex
number types, but if passing structs by value is required, you'll need
to add some C glue.

It's stored just like two floating-point numbers mashed together.
It's bit-compatible with

struct z { double re; double im; };

but you can treat it as a single value.

I was thinking of dealing with the C complex array as, say, an array
of (unsigned 128), and then including some C glue that casts it
appropriately, like this:

typedef struct { double re; double im; } z_t;
void
zconverter (double* re, double* im, z_t thing)
{
 double _Complex* thingptr = (double _Complex*) &thing;
 *re = creal ( *thingptr );
 *im = cimag ( *thingptr );
}

(defcfun "zconverter" :void (re :pointer) (im :pointer) (thing ???))

(defun zconvert (thing)
 (with-foreign-objects ((re :double) (im :double))
   (zconverter re im thing)
   (the '(complex double-float) (complex (mem-ref re :double)
(mem-ref im :double)))))

Would this be a start?

Best,
mfh
_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to