Still learning the ropes of the SICStus Prolog 4 FFI to C, I'm having a specific question about the example predicate c1/2 in https://sicstus.sics.se/sicstus/docs/latest4/html/sicstus.html/Foreign-Code-Examples.html#Foreign-Code-Examples.
ex.pl includes the line:
foreign(c1, c, c1(+integer, [-integer])).
and ex.c includes the following snippet:
/* c1(+integer, [-integer]) */
SP_integer c1(a)
SP_integer a;
{
return(a+9);
}
This works for small integers:
| ?- c1(100,X).
X = 109 ?
yes
| ?- c1(100000000000000,X).
X = 100000000000009 ?
yes
It does not work for big integers:
| ?- c1(10000000000000000000000000,X).
X = 1590897978359414793 ?
yes
How can I handle both small and big integers correctly (and efficiently)? IIRC big integers cannot be passed as "SP_integers", so should I pass these values as terms ("SP_term_ref") and do suitable dynamic type checks (possibly followed by data extraction)? Help, please!