On 13-Jun-09, at 4:48 PM, Aditya Godbole wrote:
On Sat, Jun 13, 2009 at 5:01 PM, Marc Feeleyfeeley@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.
<snip> > 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 gambit.h?
Yes. The logic in gambit.h will define a C main function when the link file (i.e. the foo_.c file produced by gsc -link foo.scm) is compiled without the -D___LIBRARY flag. That main will indirectly call ___setup to get the program running.
So when the -D___LIBRARY flag is used, the call to ___setup (and the "main" function) must appear elsewhere.
Maybe it would be better (easier for the programmer) if the following were done: ...
Thanks for the suggestion. This however doesn't seem to save much work and it introduces an extra file (scmlib_.h), which makes the whole process a bit more cumbersome. Moreover Gambit will soon have a way to run independent instances of Gambit in the same process (possibly in different threads), and your suggestion would not work in that context.
#define ___VERSION 404004
Why is this definition required? Is it just a form of a check to alert against using different versions?
Yes it is a consistency check that the client which is using Gambit (i.e. the "C application") is using the API for the required version. The version information also allows gambit.h to chose to include the correct gambit.h by a cascading mechanism (this is not used much, and you have to set it up manually). If the v4.4.4 gambit.h is in your include path, and you do a #define ___VERSION 404003 before the #include "gambit.h", then the file "gambit-not404004.h" will be included. If you have renamed the v4.4.3 gambit.h to gambit- not404004.h then you will be able to compile code with the v4.4.4 and v4.4.3 Gambit compilers.
Marc