users-prolog
[Top][All Lists]
Advanced

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

access list elements from C code


From: dmaugis
Subject: access list elements from C code
Date: Sat, 23 Jun 2012 04:57:02 -0700 (PDT)

Well...I m trying to access list element from C code, and obviously there is
something I miss-understood, because I crash. any help/explanation would be
welcome.

On the gprolog side I have:

:-foreign(sdl_init(+term)).

initialise :- 
                sdl_init([timer,audio,video]).

On the C side:

int             sdl_init(PlTerm list)
{
        unsigned long flags=0;
        if(Pl_Builtin_List(list)) {
                PlTerm *terms=NULL;
                int len=Pl_List_Length(list);
                terms=malloc(sizeof(PlTerm)*len);
                if(terms) {
                        unsigned i=Pl_Rd_Proper_List_Check(list, terms);
                        for(i=0; i<len; i++) {
                                char* s;
                                switch(Pl_Type_Of_Term(terms[i])) {
                                case PL_INT:
                                        printf("integer.\n");
                                        flags|=Pl_Rd_Integer(terms[i]);
                                        break;
                                case PL_ATM:
                                        s=Pl_Atom_Name(terms[i]);
                                        printf("atom 
'%s'\n",Pl_Is_Valid_Atom(terms[i]) ? "valid":"invalid");
                                        break;
                                }
                        }
                        
And I get:

| ?- go.
atom 'invalid'
Fatal Error: Segmentation Violation

it seems when doing :

s=Pl_Atom_Name(terms[i]);



-- 
View this message in context: 
http://old.nabble.com/access-list-elements-from-C-code-tp34058672p34058672.html
Sent from the Gnu - Prolog - Users mailing list archive at Nabble.com.




reply via email to

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