chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Re: easyffi usage


From: Thomas Chust
Subject: Re: [Chicken-users] Re: easyffi usage
Date: Tue, 08 Jul 2008 19:28:39 +0200
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.15) Gecko/20080621 SeaMonkey/1.1.10

William Xu wrote:

[...]
Hm, this seems hiding the error. Now, my_pi is 0.0, [...]

Hello,

well, of course my_pi is zero in your code, because you never set its value to anything else than its default initializer, which is zero in almost any sensible C compiler.

You write

    (foreign-declare "
    double my_pi;
    ")

    (foreign-parse "
    double my_pi = 3.14;
    ")

which means "Include 'double my_pi;' verbatim in the C code, parse 'double my_pi = 3.14' as a C declaration and generate Scheme bindings for it". The parser of easyffi discards the initializer, because it is none of its business to deal with it. That would be the job of the C compiler, but the C compiler never gets to see the constant 3.14.

You should either write

    (foreign-parse "
    double my_pi;
    ")

    (foreign-declare "
    double my_pi = 3.14;
    ")

or simply

    (foreign-parse/declare "
    double my_pi = 3.14;
    ")

to achieve the desired effect.

cu,
Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]