[mercury-users] Automatic module initialisation?

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Feb 19 19:27:49 AEDT 1999


On 19-Feb-1999, Warwick Harvey <wharvey at cs.monash.edu.au> wrote:
> 
> Is it possible to get Mercury to automatically call an initialisation 
> predicate/function for a module at start-up?

You and Peter Schachte have been plotting together, haven't you? ;-)

Out of curiousity, why do you need an initialisation function?

As recently discussed on this list, Mercury does not officially
support that kind of thing at the moment.  However, the implementation
does have some mechanisms for doing this kind of thing.  The details
are described below.  Of course, if you rely on this, then you are
relying on implementation details that could perhaps change in some
future release.

> I had thought that getting an `INIT' line into the C code of the module 
> (specifying a C function to call) would do the trick.  The semantics of this 
> line have changed since I last fiddled with something like this, but I found 
> the `--extra-inits' flag for c2init, which did get a reference to my 
> initialisation function to appear in the program's _init.c file.  However, 
> the initialisation function does not appear to be being called (even if I 
> specify `--include-initialization-code' for c2init, if that has any bearing).

Using an "INIT' line in the C code is not enough; you have to also use
the `--extra-inits' and the `--include-initialization-code' options,
as you did, and in addition your program startup then needs to call
the function do_init_modules(), which is declared in one of the
header files included by "mercury_imp.h".

(This will almost certainly change in some future release -- the function
ought to be renamed MR_do_init_modules().)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the users mailing list