interfacing with c - unification of pointers to structures

View: New views
2 Messages — Rating Filter:   Alert me  

interfacing with c - unification of pointers to structures

by Tushar Parekh-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
hello,

i have interfaced gnu prolog and c libraries.

i am able to handle input, output arguments of simple types like string, integer.

i have a structure in c program e.g. BITMAP.  i want to return a pointer to this structure
i.e. BITMAP * back to gnu prolog from c function.  how do i code this ?
i am working on 32 bit machine.  so all pointers are 32 bits.  i am able to handle integer output
arguments by declaring int * on c function side and setting this to the integer value and returing
PL_TRUE to enable binding to prolog argument.  can i cast BITMAP * to INTEGER * and send it
back to gnu prolog.  the reason i need to store this pointer on prolog side is to facilitate future calls
to c functions with this pointer supplied as an argument.


thank you in advance for any help.

regards,
tushar parekh.



Ask a question on any topic and get answers from real people. Go to Yahoo! Answers.
_______________________________________________
Users-prolog mailing list
Users-prolog@...
http://lists.gnu.org/mailman/listinfo/users-prolog

Re: interfacing with c - unification of pointers to structures

by Daniel Diaz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello,

since gprolog ints are not coded on signed 29 bits it is difficult to ensure you can encode a pointeur as a Prolog integer. Some possible solutions:
  • encode an index (0-based displacement). If not possible, use an array in C where you store the pointer then you pass the index inside this array
  • encode it as a Prolog float (C double).
  • encode it as a Prolog structure of 2 integers (2 x 16 bits)
  • encode it as an atom (only if there is a limited set of pointers to handle).
Daniel


Tushar Parekh a écrit :
hello,

i have interfaced gnu prolog and c libraries.

i am able to handle input, output arguments of simple types like string, integer.

i have a structure in c program e.g. BITMAP.  i want to return a pointer to this structure
i.e. BITMAP * back to gnu prolog from c function.  how do i code this ?
i am working on 32 bit machine.  so all pointers are 32 bits.  i am able to handle integer output
arguments by declaring int * on c function side and setting this to the integer value and returing
PL_TRUE to enable binding to prolog argument.  can i cast BITMAP * to INTEGER * and send it
back to gnu prolog.  the reason i need to store this pointer on prolog side is to facilitate future calls
to c functions with this pointer supplied as an argument.


thank you in advance for any help.

regards,
tushar parekh.



Ask a question on any topic and get answers from real people. Go to Yahoo! Answers.
--
Ce message a été vérifié par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a été trouvé.


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


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