[cffi-devel] C compilation error on sizeof structure

Stelian Ionescu sionescu at cddr.org
Fri Sep 21 21:16:03 UTC 2012


On Fri, 2012-09-21 at 16:27 -0400, Mirko Vukovic wrote:
[...]
> struct triangulateio {
>   REAL *pointlist;                                               /* In / out */
>   REAL *pointattributelist;                                      /* In / out */
>   int *pointmarkerlist;                                          /* In / out */
>   int numberofpoints;                                            /* In / out */
>   int numberofpointattributes;
>   ....
>   }
> 
> I defined a groveller lisp file libtriangle-unix.lisp with the
> following contents:
> 
> (define REAL "double")
> (include "/home/mv/external-libraries/c-code/triangle/triangle.h")
> 
> (cstruct triangulateio "triangulateio")

that needs to be (cstruct triangulateio "struct triangulateio")

> 
> (Note that I did not specify any fields.  I saw a post on the web
> suggesting that cffi would fill it in.  Is that correct?)

No, you must declare all fields you're interested in. What the groveler
does for you is figuring out the struct's total size and the fields'
offsets. It's even ok if you don't declare all fields the actual struct
contains
Example: https://github.com/sionescu/iolib/blob/master/src/syscalls/ffi-types-unix.lisp#L401
struct dirent can, and on some OSes, does have other fields but I only
use the ones I listed there

-- 
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.
http://common-lisp.net/project/iolib

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20120921/553fdea7/attachment.sig>


More information about the cffi-devel mailing list