![](https://secure.gravatar.com/avatar/9ed6ab1d1019fe41799ee83440518e36.jpg?s=120&d=mm&r=g)
Frank Goenninger <fgoenninger@prion.de> writes:
I do habe C structs lile these:
struct a_struct { int a; };
struct b_struct { int b; struct a_struct a; };
How would I model b_struct using defcstruct ?
It looks like what you would think: (defcstruct a-struct (a :int)) (defcstruct b-struct (b :int) (a a-struct)) It's confusing, because CFFI tries to avoid passing aggregate C objects by value. For instance, if you declare a function argument as having type A-STRUCT, you get a pointer instead, because you can't pass structures by value in CFFI. But in a structure, you do need to able to include a structure, not just a pointer to it. So the obvious thing does what you want. In retrospect, the foreign type A-STRUCT should probably always mean the structure itself by value, and declaring a function like: (defcfun struct-by-value :void (a a-struct)) should probably just be an error, instead of the DWIM-ish behavior of canonicalizing A-STRUCT to :POINTER. (And someday the Lisp implementations may be extended to pass structures by value, and we will want to support that.) Ideally, :POINTER should probably become a parameterized type, so that function would instead be: (defcfun struct-by-pointer :void (a (:pointer a-struct)) which will help us down the road when we implement optional pointer type checking. Any thoughts? This would be a pretty incompatible change, but it's probably better to fix it soon then let more code get written that takes advantage of this (IMHO) misfeature. James