[mercury-users] Mercury and C
Drirr C.
00444083 at academ01.cem.itesm.mx
Tue Nov 12 16:17:40 AEDT 2002
Hello,
I'm writing a program using Mercury and C, however I haven't been able to
return a string from the c function.
I have something like this:
:- pred buildPoly(int::in, int::in, int::in, int::in, string::out) is det.
...
:- pragma c_code(buildPoly(VARS::in,TERMS::in,NEG::in,SEED::in,OUT::out),
[may_call_mercury], "buildPoly(VARS,TERMS,NEG,SEED,OUT);").
And then something like this:
void buildPoly(MR_Integer variables, MR_Integer terms, MR_Integer
negations, MR_Integer seed, MR_Word result) {
...
buffer = (char*)malloc(...);
...
*((char **)result) = buffer;
}
As far as I understand from the documentation, Mercury passes an address
where the result must be put. However, "result" contains an invalid address
when buildPoly is called.
And a result is only returned by the c function either when it can fail or
when it's a function (not a predicate), hence the void in buildPoly. Am I
right?
Any suggestions?
Thanks
Drirr C.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list