[gambit-list] c-lambda fun

lowly coder lowlycoder at huoyanjinjing.com
Fri Feb 13 23:45:32 EST 2009


~/error$ cat comp.scm
(c-declare #<<end
typedef struct foo
{
 int x, y;
} foo;

foo global_foo;

//foo* get_foo(const char* s)
foo* get_foo(int)
{
 return &global_foo;
}

foo* get_str_foo(const char* s)
{
 return &global_foo;
}

int add(int x)
{
 return x + 2;
}

end
)


(c-define-type foo "foo")
(c-define-type void* (pointer void))
(c-define-type foo* (pointer foo))
(define add (c-lambda (int) int "add"))
(define get-foo (c-lambda (int) foo* "get_foo"));
(define get-foo2 (c-lambda (int) void* "get_foo"));
(define get-str-foo2 (c-lambda (char-string) void* "get_str_foo"));
(define get-str-foo (c-lambda (char-string) foo* "get_str_foo"));


~/error$ cat make.scm
#!/usr/local/Gambit-C/bin/gsc -i

(compile-file-to-c "comp")
(link-flat '("comp") output: "comp.o1.c")
(shell-command "g++ -shared -D___DYNAMIC -fPIC comp.c comp.o1.c -o comp.o1")


~/error$ cat int.scm
(load "comp")
(pp (add 2))
(pp (get-foo2 2))
(pp (get-foo 2))
(pp (get-str-foo2 "hello"))
(pp (get-str-foo "world"))



Question: what's the difference between get-str-foo2 and get-foo2 that
causes one to work and one throw an error?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20090213/c67bb0a1/attachment.htm>


More information about the Gambit-list mailing list