Subject: [clisp-list] FFI question: returning array of "C" structs

From: "John K. Hinsdale" <[email-masked]>
Date: Mon Aug 5 07:59:05 2002

I'm writing an external "C" function called from CLISP via the FFI and
I want my "C" function to return an array of some variable number of
structs from "C".  How do I do that?

My function fills in an array of structs (not pointers, whole structs,
and also returns a count of how many it allocated and filled in, i.e.:

struct extcol * col_info()

I've got a separate function "ncol()" that can be called to get the
count from Lisp so it knows how many to read in.

Where I'm stuck is how to declare the return tyep of my function.

The docs mention a "C-ARRAY-PTR"

	(FFI:C-ARRAY-PTR c-type) This type is equivalent to what C
	calls c-type (*)[]: a pointer to a zero-terminated array of items of
	the given c-type.

but I'm confused as to whether this means I'm declaring a pointer to
(1) the base of an array of "c-types" or to (2) the base of an array
of "pointer to c-types"

The "zero-terminated" blurb in the comments suggests (2) - how could
you zero-terminate an array of structs, however, looking at examples
of modules distributed with CLISP suggests (1) ...
	
any ideas?

---
John Hinsdale, Alma Mater Software, Inc., Tarrytown, NY 10591-3710 USA
[email-masked] | http://www.alma.com/staff/hin | +1 914 631 4690