[plt-scheme] Binding C-Structs Containing Fixed-Size Arrays with the FFI

From: Henk Boom (lunarc.lists at gmail.com)
Date: Sun Jan 25 22:38:35 EST 2009

I'm trying to bind parts of ODE[1] with the FFI, but I've ran into an
issue I haven't had to face before, and I haven't been able to resolve
by looking at the FFI documentation. Take a look at the type

typedef float dReal;
typedef dReal dVector3[4];
typedef struct dJointFeedback {
  dVector3 f1;		/* force applied to body 1 */
  dVector3 t1;		/* torque applied to body 1 */
  dVector3 f2;		/* force applied to body 2 */
  dVector3 t2;		/* torque applied to body 2 */
} dJointFeedback;

Now, as I understand it, dJointFeedback structs will basically contain
16 floats. I'm not sure how I should be binding this, though. The
closest thing I have found looking through the documentation is
_cvector[2], but that seems to actually wrap arrays-as-pointers, which
would only let me define structs containing 4 float pointers, which
doesn't work out.

How should I handle this?

[1] http://ode.org/
[2] http://docs.plt-scheme.org/foreign/foreign_procedures.html#(form._((lib._scheme/foreign..ss).__cvector))

Posted on the users mailing list.