[gambit-list] calling scheme from C

Aditya Godbole aag.lists at gmail.com
Sat Jun 13 16:48:25 EDT 2009

On Sat, Jun 13, 2009 at 5:01 PM, Marc Feeley<feeley at iro.umontreal.ca> wrote:
> I've tried to come up with a simpler example than server.scm/client.c to
> explain how to write the C and Scheme code.

Thanks, I've got it working with a few minor modifications like the -I
and -L flags to gcc. I still have a couple of questions (and a
suggestion), mentioned below.

>    int stdio_settings;         /* default stdio I/O settings */
>    ___mod_or_lnk (*linker) ___P((___global_state_struct*),());  /* linker C
> function */

Do we need to provide this linker function because the entry point of
the executable is generated from our code, instead of the code in

Maybe it would be better (easier for the programmer) if the following were done:


#define ___setup_params_reset(x) _setup_params_reset((x),___SCHEME_LIB_LINKER)

The _setup_params_reset sets the value of linker if

scmlib_.h (generated by gsc along with scmlib.c and scmlib_.c):
#define ___SCHEME_LIB_LINKER ___20_scmlib_

extern ___mod_or_lnk ___SCHEME_LIB_LINKER (___global_state_struct*);
Using the above method, the end programmer would only have to include
scmlib_.h, instead of being bothered with the all the #defines. If
required he would still be able to set the ___SCHEME_LIB_LINKER
manually (maybe a macro ___setup_linker could be provided for that).
The above scheme will also maintain compatibility with earlier code
(unless someone has explicitly defined ___SCHEME_LIB_LINKER, in which
case another obscure name could be chosen).

The C code would then look like:
#define ___VERSION 404004
#include "gambit.h"
#include "scmlib_.h"
#include <stdio.h>

/* The definition below could also go into scmlib_.h */
extern int hello( char *str );  /* defined in scmlib.scm */

int main( int argc, char **argv )
 ___setup_params_struct setup_params;

 ___setup_params_reset( &setup_params );

/* This could also be engulfed by the wrapper macro suggested above */
 setup_params.version = ___VERSION;

 ___setup( &setup_params );  /* setup Scheme library */

 printf( "returned %d\n", hello( "montreal" ) );
 printf( "returned %d\n", hello( "world" ) );

 ___cleanup();  /* cleanup Scheme library */

 return 0;

> #define ___VERSION 404004

Why is this definition required? Is it just a form of a check to alert
against using different versions?


More information about the Gambit-list mailing list