[mercury-users] using univ with C

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Jun 5 12:33:36 AEST 2008


On Thu, 5 Jun 2008, QRL_Charles QRL_Gretton wrote:

> Q: How can I access the data of a Mercury ":-type univ" in C?

Is the question, how do I get the thing inside a univ in C, or
what is the type of a univ in C?

> If my question doesn't make sense, the following might explain what
> I'm after a bit better.
>
> Imagine if "univ" was a C void pointer. Then, for a Mercury interface
> to a dynamically polymorphic list in C, I could have:
>
> :- pred push_back_c_vector(univ::in, c_vector::in, int_store::mdi,
> int_store::muo) is det.
>
> :- pragma foreign_proc("C",
>        push_back_c_vector(Univ::in, Vector_In::in,S0::mdi, S::muo),
>        [promise_pure],
> "
> 		      Vector_In->push_back(Vector_In, Univ);
> 		      S = S0;
> ").

The type of univ in C is MR_Word, which is an unsigned integral type
such that sizeof(MR_Word) == sizeof(void *), so the above code should
work (assuming the C list is defined as I think it is.)

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