Re: [eclipse-clp-users] Function call

From: Joachim Schimpf <jschimpf_at_...311...>
Date: Sat, 17 Mar 2012 01:52:37 +0100
Christian Giffhorn wrote:
> ...
> 
> "#include "eclipseclass.h
> 
> int main()
> {
>                 ec_init();
> 
> 		EC_ref States;
> 	
> 		post_goal(term(EC_functor("=",2), States, EC_atom("S")));
> 		
>         post_goal(term(EC_functor("compile",1),"//Z/exchange/PrologTest/Golog/elevator.pl"));
> 
>         if(EC_resume() != EC_succeed)
> 		{
> 			cout << "Compilation failed" << endl;
> 			exit(-1);
> 		} else
> 		{
> 			cout << " Compilation succes" << endl;
> 		};
> 
> 		
> 		post_goal(term(EC_functor("do",3), EC_atom("control"),
> EC_atom("s0"), States));
> 		
> 		if(EC_resume() != EC_succeed)
> 		{
> 			cout << "succees" << endl;
>         }
> 
>         ec_cleanup();
> 	return 0;
> }
> 
> That how i think it should work, but at the end of compilation the
> program crashes, and the debugger leads me to the deconstructor of the
> ref(i can even make a cout happen after the cleanup).


Hi Christian,

The crash happens because the deconstructor for the EC_ref is called
after ec_cleanup().  To make it happen before, use an extra block
to enclose your EC_ref declarations:

int main()
{
     ec_init();
     {
         EC_ref States;
         <your other code>
     }
     ec_cleanup();
     return 0;
)

Alternatively, you could omit the ec_cleanup() altogether.


-- Joachim
Received on Sat Mar 17 2012 - 00:52:47 CET

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST