Depending on the struct layout before foo, this segfaults added by C-Keen on Tue Jan 3 22:00:20 2012
(import foreign) (foreign-declare #<<EOF typedef struct { double x; double y; int foo; } c_struct_t; void fill_struct (c_struct_t* s, int val){ s->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)))