Res: [mercury-users] Passing structures from and to C

Peter Wang wangp at students.csse.unimelb.edu.au
Wed Jul 11 10:34:21 AEST 2007


On 2007-07-10, Alexsandro Soares <a_s_soares at yahoo.com.br> wrote:
> Thanks by the answers.
> 
> For others beginner Mercury programmers, such as myself, I put here my final code:
> 

> :- func getName(person) = string.
> 
> :- pragma foreign_proc("C", 
>      getName(P::in) = (Name::out),
>      [will_not_call_mercury, thread_safe, promise_pure],"
> {
>     Name = (MR_String) strdup(P->name);
> }").

This memory won't be reclaimed.  You can use MR_make_aligned_string_copy*
from mercury_string.h, although it's undocumented.

Peter
--------------------------------------------------------------------------
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