[cffi-devel] C99 complex datatypes?
Mark Hoemmen
mark.hoemmen at gmail.com
Sun Oct 15 16:19:07 UTC 2006
On 10/15/06, Luís Oliveira <luismbo at gmail.com> 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
More information about the cffi-devel
mailing list