(import foreign) (foreign-declare #<foo = val; } EOF ) (define-foreign-variable sizeof-c-struct size_t "sizeof(c_struct_t)") (define-record c-struct-type buffer) (let ((maker make-c-struct-type)) (set! make-c-struct-type (lambda () (maker (make-blob sizeof-c-struct))))) (define-foreign-type c-struct-t scheme-pointer) (define fill-struct (foreign-lambda void "fill_struct" c-struct-t int)) (define c-struct-t-foo (foreign-lambda* int ((c-struct-t t)) "C_return(((c_struct_t*)t)->foo);")) (print "sizeof c struct: " sizeof-c-struct) (let loop ((i 0)) (let ((s (make-c-struct-type))) (fill-struct s i) (print i " == " (c-struct-t-foo s))) (loop (add1 i)))