Node:Conversions between Prolog Arguments and C Types, Next:Interface Predicates, Previous:Conversion Declarations, Up:Calling C from Prolog
The following table lists the possible values for the arguments in
the predicate specification of foreign/[2,3]
. The value
declares which conversion between corresponding Prolog argument
and C type will take place.
Please note: here, the term chars
refers to a code-list,
rather than to a char-list.
Prolog: +integer
C: long
long
and passed to the C function.
Prolog: +float
C: double
double
and
passed to the C function.
Prolog: +atom
C: SP_atom
Prolog: +chars
C: char *
Prolog: +string
C: char *
Prolog: +string(N)
C: char *
Prolog: +address
C: void *
void *
pointer.
Prolog: +address(TypeName)
C: TypeName *
TypeName *
pointer.
Prolog: +term
C: SP_term_ref
Prolog: -integer
C: long *
long
.
The value returned will be converted to a Prolog integer.
Prolog: -float
C: double *
double
.
The value returned will be converted to a Prolog float.
Prolog: -atom
C: SP_atom *
SP_atom
.
The value returned should be the canonical representation of a
Prolog atom.
Prolog: -chars
C: char **
char *
.
The returned encoded string will be converted to a Prolog code-list.
Prolog: -string
C: char **
char *
.
The returned encoded string will be converted to a Prolog atom. Prolog
will copy the string to a safe place, so the memory occupied by the
returned string may be reused during subsequent calls to foreign
code.
Prolog: -string(N)
C: char *
Prolog: -address
C: void **
void *
.
Prolog: -address(TypeName)
C: TypeName **
TypeName *
.
Prolog: -term
C: SP_term_ref
Prolog: [-integer]
C: long F()
long
. The value returned will be
converted to a Prolog integer.
Prolog: [-float]
C: double F()
double
. The value returned will
be converted to a Prolog float.
Prolog: [-atom]
C: SP_atom F()
SP_atom
. The value
returned must be the canonical representation of a Prolog atom.
Prolog: [-chars]
C: char *F()
char *
. The returned encoded
string will be converted to a Prolog code-list.
Prolog: [-string]
C: char *F()
char *
. The returned encoded
string will be converted to a Prolog atom. Prolog will copy the string
to a safe place, so the memory occupied by the returned string may be
reused during subsequent calls to foreign code.
Prolog: [-string(N)]
C: char *F()
char *
. The first N bytes
of the encoded string (not necessarily NULL-terminated) will be copied
and the copied string will be stripped of trailing blanks. The stripped
string will be converted to a Prolog atom. C may reuse or destroy the
string buffer during later calls.
Prolog: [-address]
C: void *F()
void *
.
(see Creating Prolog Terms), will be converted to a Prolog integer.
Prolog: [-address(TypeName)]
C: TypeName *F()
TypeName *
.
Prolog: [-term]
C: SP_term_ref F()