Re: [Chicken-users] Passing floats to and from foreign functions

2013-05-11 Thread Jim Ursetto
Hi pluijzer .,

You did not declare a prototype in test.scm (technically, test.c) for the 
functions in wrapper.c.  I believe return values default to int if there is no 
prototype, and the float arg is promoted to double, but I'm not positive.

Anyway, simply add the following to the top of test.scm:

#>
float testGet();
void testSet(float);
<#

Alternatively, put those declarations in wrapper.h and #include it from 
test.scm.

#> #include "wrapper.h" <#

By the way, you don't need easyffi in your test, as you're not using it.

Jim

P.S.

Passing -Wall to the compiler might help discover these errors.  By default, 
clang gives the following output:

test.c:31:19: warning: implicit declaration of function 'testGet' is invalid in 
C99 [-Wimplicit-function-declaration]
C_r=C_flonum(&C_a,testGet());
  ^
test.c:39:1: warning: implicit declaration of function 'testSet' is invalid in 
C99 [-Wimplicit-function-declaration]
testSet(t0);

On May 11, 2013, at 7:14 PM, "pluijzer ."  wrote:

> Hello everybody,
> I'm having trouble passing floating point numbers to and from foreign 
> functions.
> 
> This is what I'm doing:
> 
> -- test.scm --
> 
> (require-extension easyffi)
> (print ((foreign-lambda float "testGet")))
> ((foreign-lambda void "testSet" float) 4.0)
> (print ((foreign-lambda float "testGet")))
> 
> -- wrapper.c --
> 
> float a = 5.0;
> void testSet(float value) { a = value; }
> float testGet(void) { return a; }
> 
> What I get is this:
> 
> > csc -X easyffi wrapper.c test.scm
> > ./test
> -1080529876.0
> -1080533140.0
> 
> But I expected the output to be:
> 4.0
> 5.0
> 
> I'm I doing something wrong/forgetting something?
> When I use integers instead of floats I do get the desired result.
> 
> Thank you in advance,
> Righard
> 
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Passing floats to and from foreign functions

2013-05-11 Thread John Cowan
pluijzer . scripsit:

> I'm having trouble passing floating point numbers to and from foreign
> functions.

That is because Scheme inexact numbers correspond to C doubles, not C
floats.  There is no support in Chicken for C floats.

-- 
John Cowan http://www.ccil.org/~cowan
Charles li reis, nostre emperesdre magnes,
Set anz totz pleinz ad ested in Espagnes.

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users