[mercury-users] list of floats C interface problem

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Jun 18 18:37:21 AEST 2010


Hi James,

On Fri, 18 Jun 2010, James Cussens wrote:

> The following program returns junk rather than the expected 3.0. If all the 
> floats are changed to ints all is well. Can anyone help me understand what's 
> going on? I'm using mercury-compiler-rotd-2010-04-17

On some** systems Mercury needs to box floats (which for Mercury are
usually C doubles).  The runtime provides the macros:

    MR_word_to_float()
    MR_float_to_word()

for doing this conversion if it is required.

When inserting or removing floats from Mercury data structures, you will
need to do something like the following for your example:

     :- pragma foreign_proc("C",
         test2(Probs::in, Tot::out),
         [will_not_call_mercury, promise_pure],
"
     Tot = MR_word_to_float(MR_list_head(Probs));
").

(The reference manual doesn't describe this, but should - I will look
into fixing it.)

Julien.

** some systems means 32-bit systems and 64-bit systems where Mercury
has been configured not to use unboxed floats.
--------------------------------------------------------------------------
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