bug-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gplc doesn't work properly with gcc 4.x.x


From: Idomeneo
Subject: gplc doesn't work properly with gcc 4.x.x
Date: Wed, 1 Oct 2008 17:41:21 +0200

Hello,

***MY SYSTEM***

I'm working on a i686 AMD Sempron 2400+ under Archlinux, I'm using gcc 4.3.2 and gprolog 1-3.0 (the lastest stable version available right now).
I would like to interface C and Prolog in order to make a solver for some puzzle (written in C) and learn about constraint programming.

***MY ISSUE***

So I've carefully read the manual's last chapter and I've tried out the examples in there before going to build up mine, but even some of them don't work properly with gcc 4.3.2!

****EXAMPLE****

The last one in gprolog's manual ( section 9.5.1, you can find the source new_main_c.c as far as I know located in ExamplesC folder).

Let's look function Main_Wrapper in there:

***CODE****

static int
Main_Wrapper(int argc, char *argv[])
{
  int func;
  WamWord arg[10];
  char str[100];
  char *sol[100];
  int i, nb_sol = 0;
  Bool res;
  Start_Prolog(argc, argv);
  func = Find_Atom("anc");
  for (;;)
    {
      printf("\nEnter a name (or 'end' to finish): ");
      scanf("%s", str);
      if (strcmp(str, "end") == 0)
        break;
      Pl_Query_Begin(TRUE);
      arg[0] = Mk_Variable();
      arg[1] = Mk_String(str);
      nb_sol = 0;
      res = Pl_Query_Call(func, 2, arg);
      while (res)
        {
          sol[nb_sol++] = Rd_String(arg[0]);
          res = Pl_Query_Next_Solution();
        }
      Pl_Query_End(PL_RECOVER);
      for (i = 0; i < nb_sol; i++)
        printf(" solution: %s\n", sol[i]);
      printf("%d solution(s)\n", nb_sol);
    }
  Stop_Prolog();
  return 0;
}

***END CODE***

**** MY EXPLANATION ****

If I run this simple example asking for the john's ancestors list (for further information please look at the prolog file new_main.pl), it simply answers with "peter" while the correct answer was: peter, bob, jane, mary and paul !! 

I guess that function Pl_Query_Next_Solution() (look in the while(res) ) doesn't work properly: it always returns FALSE even if there is more than one solution! That's awful, you can't go further than the first result in the query because res is set equal to 0 in the while(res) at the very first attempt (so the while condition becomes FALSE)!

The only workaround I was able to find out is just to install gcc 3.x.x and try again and it worked flawlessly! :-)
Although the query works fine in that way, I'd still prefer using gcc 4.x.x if I could find out how to!

Any suggestions would be nice! Thanks.

Idomeneo

p.s. sorry for my BAD English, actually I'm still learning it! Anyway, I hope my message is still intelligible to all of yours. :-D



reply via email to

[Prev in Thread] Current Thread [Next in Thread]