On Sat Apr 11, 2026 at 4:07 AM CEST, Paul Wisehart via Chicken-users wrote:
> Hi!
>
> I have been using basic ffi successfully.
>
> Now I am trying to level up and call a scheme
> defined function from C.
>
> I am looking here:
>
> https://wiki.call-cc.org/man/5/Module%20(chicken%20foreign)#callbacks
>
> I set up a basic example here:
>
> https://codeberg.org/pkw/chicken-learn/src/branch/main/c-callbacks
>
> -------------
>
> I am trying it in two ways and they both fail with:
>
> home:~/code/scm/learn/c-callbacks$ ./main.exe fn1
> fn1
>
> Error: (location) bad argument type - locative cannot refer to objects of
> this type: #<procedure (interface#cb2)>
Hi!
I think the problem is that your use of "location" ("#$") refers to a callback
defined outside of the current module. An entity defined with "define-external"
has actually two representations: a normal Scheme procedure and some information
that this is a foreign entry point. The module system doesn't know about this
extra information and just exports the Scheme binding. So you should use
"location" to obtain the callback address in the same source file which
defines the entry point.
This is a general restriction of the module system: it only knows about Scheme
procedures and syntax, but not about foreign variables and entry-points.
You could, for example, define some wrappers in your "interface" module
that return the location.
cheers,
felix