Re: another problem interfacing prolog and C

Erick Alphonse <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Hello Daniel,

Daniel Diaz wrote:
> the problem comes from the fact you invoke Prolog from your call_c/2
>  foreign code. This one uses 2 arguments (a and _L) which are stored
> into an array (accessible via macros X(0) and X(1)). But since
> write/1 itself is partly written in Prolog it also uses X(...)
> variables. So, the clean way to fix it would be to inform the
> compiler a foreign code calls Prolog (and thus the compiler would
> emit code to save/restore the X(...) vars used).
> 
> For the moment you can do it by hand (okay it is a bit dirty) as
> follows:

Thanks a lot for your help and the explanations!

I have another question. In the documentation, you explain another way 
to output results:

> When +term is specified the term passed to the function is the
> original Prolog term. It can be read and/or unified. It is also the
> case when term is specified without any mode symbol.

and use this in one of your examples.

Do we need to save/restore the X() vars in that case too, or only when 
we pass pointers to the C function (like -term or +string).

 > So, the clean way to fix it would be to inform the
 > compiler a foreign code calls Prolog (and thus the compiler would
 > emit code to save/restore the X(...) vars used).

If you want to talk about this issue further, I would be very interested 
to do so with you.

Thanks again,
Best regards,
Erick.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.