users-prolog
[Top][All Lists]
Advanced

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

Re: calling c from gprolog


From: Daniel Diaz
Subject: Re: calling c from gprolog
Date: Thu, 05 Jun 2003 15:04:18 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01

Output arguments are handled with a pointer to the type. E.g. a output integer (-integer) is handed as: int *pout. Similarly a string (char *) is handled as a char **pout. Here is a correct version of your example:


#include "gprolog.h"

Bool test(char *in, char **pout){

  *pout = (char *) malloc(1024*sizeof(char));

  sprintf(*pout, "teste");
  printf("IN:%s\n", in);

  return TRUE;          /* succeed */
};




Pedro Salgueiro wrote:
Hi.
I'm trying to call c from gprolog and I have some
problems when I use the foreign type "-string" to
obtain the result of the c function.

This the file teste.c:

#include "gprolog.h"

Bool test(char *in, char *out){

  //out = (char *) malloc(1024*sizeof(char));
  //out = (char *) alloca(1024);

  sprintf(out, "teste");
  printf("IN:%s\n", in);
return TRUE; /* succeed */
};


And this is the file test.pl

:- foreign(test(+string,-string)).

when I compile both of them with:
gplc test.c test.pl
I get an executable file.
When I run this file and enter "test(xpto, X)."
gprolog just crahs, with the folowing error:

Fatal Error: Segmentation Violation

Anyone knows how to put this little exmaple working.

Thank's.
Pedro Salgueiro


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com


_______________________________________________
Users-prolog mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/users-prolog

--
Ce message a subi une analyse antivirus par MailScanner ; il est vraisemblablement
sans danger.






--
Ce message a subi une analyse antivirus par MailScanner ; il est vraisemblablement
sans danger.





reply via email to

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