[mercury-users] number of args for bag.init exported to C

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Jun 8 11:34:05 AEST 2011


On Tue, 7 Jun 2011, Guillaume Yziquel wrote:

> I'm exporting the bag.init function with the following pragma:
>
> 	:- pragma foreign_export("C", bag.init(out), "no_props").
>
> And the C function prototype that is exported is:
>
> 	void no_props(MR_Word, MR_Word *);
>
> What is the meaning of the first argument? There is no 'in' argument in
> the Mercury code, and yet it shows in the C function prototype. More
> importantly: what should I set it to?

The extra argument is the type_info (type descriptor) for the type
variable T in the bag.init/1 predicate.  This is described in the
reference manual section ``Using pragma foreign_export for C'',
specifically:

     If you do export a polymorphically typed Mercury procedure, the compiler
     will prepend one `type_info' argument to the parameter list of
     the C interface function for each polymorphic type variable in the
     Mercury procedure's type signature. The caller must arrange to pass in
     appropriate `type_info' values corresponding to the types of the
     other arguments passed. These `type_info' arguments can be
     obtained using the Mercury `type_of' function in the Mercury
     standard library module `type_desc'.

Julien.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list