Hello,
This is not a problem with Chicken nor with your use of float as
return type (float means float in Chicken, not double).
The problem is that you didn't provide a C prototype for your external
function. This is a C issue, as you will see if you write a simple C
program:
$ cat > test.c <<EOF
#include <stdio.h>
/* float baz(int); */ /* look ma, no prototype */
int main(void) { printf("baz 42: %f\n", baz(42)); }
EOF
$ gcc -o test test.c impl.c
$ ./test
$ baz 42: 0.000000
Now uncomment the prototype and it works correctly.
To fix in your case, add the following to the top of callit.scm.
#> float baz(int); <#
Under normal use, of course, you would use
#> #include <impl.h> #<
Or use foreign-lambda* and include the code inline.
On 8/27/06, Shawn Rutledge <[EMAIL PROTECTED]> wrote:
impl.c:
#include <math.h>
float baz(int i)
{
return (((float)i) / 15.2);
}
callit.scm:
(define baz (foreign-lambda float "baz" int))
(display baz)
(display (baz 42))
csc callit.scm impl.c
./callit
#<procedure (baz a25)>42.0
Change impl.c to make sure it's being called at all:
#include <math.h>
#include <stdio.h>
float baz(int i)
{
printf("baz given %d\n", i);
return (((float)i) / 15.2);
}
./callit
#<procedure (baz a25)>baz given 42
13.0
This is with chicken 2.2 and I think 2.3 also has similar problems. I
can try 2.41 when it gets done building.
_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users