Welcome to the CHICKEN Scheme pasting service
foreign library with floats pasted by klm` on Mon Jul 9 07:45:06 2012
I've got a foreign shared lib: === lib.c #include <stdio.h> void stat(float d) { printf("from c: d = %.3f, int = %d\n", d, (int)d); } I wanna use its function stat in my Scheme prog: === prog.scm (define stat (foreign-lambda void "stat" float)) (stat 123.1) I compile and run, and everything is terribly wrong: $ gcc -fPIC -shared lib.c -o lib.so $ csc prog.scm -L ./lib.so $ ./prog from c: d = 36893488147419103232.000, int = -2147483648 Why is my original 123.1 messed up? It works when I use doubles.
solution added by klm` on Mon Jul 9 08:18:19 2012
for the curious: the paste above fails because 'stat' is implicitly declared (with double I'm guessing). Declaring its signature beforehand fixes it.