~/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?
Afficher les réponses par date
On 13-Feb-09, at 11:45 PM, lowly coder wrote:
~/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?
When I run your code I get:
4 #<void* #2 0x3a1378> #<foo* #3 0x3a1378> #<void* #4 0x3a1378> #<foo* #5 0x3a1378>
So the results are the same (except for the fact that the type tag is either void* or foo*). What is the result your get?
I suspect that you did not compile Gambit using --enable-cplusplus . If you want to load code compiled by a C++ compiler, then Gambit itself must have been compiled with a C++ compiler (so that the ABI is the same).
Marc